Reputation: 9
Pyodbc is correctly connecting to the same db. When I run
SELECT name FROM sys.databases;
SELECT name FROM master.dbo.sysdatabases;
I get the list of all the DBs I can see in MSSQLSMS.
When I look at my Event Profiler in SSMS, I can see that Pyodbc is executing code actions on the same database in the same server as I look at with SSMS. I see my create table statements, select statements, that I'm running in Python with Pyodbc, executing on my SQL server.
So why can I not see the tables I've created in SSMS? Why, when I run the same queries in SSMS, do I not see the table I've created using Pyodbc?
I am extremely confused. Pyodbc appears to be connecting to my local SQL server correctly, and executing SQL code on it, but I'm not able to view the results using SSMS. I can find the table with Pyodbc, and Pyodbc and SSMS are both telling me they're looking at the same places, but SSMS can't see anything Pyodbc has done.
EDIT : Solved
conn.autocommit=True
is required for Pyodbc to make permanent changes.
Upvotes: 0
Views: 759
Reputation: 123549
SQL Server allows some DDL statements (e.g., CREATE TABLE
) to be executed inside a transaction. Therefore we also have to remember to commit()
those changes if we haven't specified autocommit=True
on the Connection.
Upvotes: 1