I've got this code:
from sqlalchemy.engine import create_engine
engine = create_engine('mssql+pyodbc://sa:[email protected]/master.db', echo=True)
connection = engine.connect()
connection.execute(
"""
CREATE TABLE users (
username VARCHAR PRIMARY KEY,
password VARCHAR NOT NULL
);
"""
)
connection.execute(
"""
INSERT INTO users (username, password) VALUES (?, ?);
""",
"foo", "bar"
)
result = connection.execute("SELECT username FROM users")
for row in result:
print "username:", row['username']
connection.close()
I'm getting this error:
sqlalchemy.exc.DBAPIError: (Error) ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53)') None None
I ran this query on my DB
select db_name()
and got this O/P
1. master
Can someone explain what is wrong in my logic?
master.db. Is this the correct name of your database? Do you want to connect to SQL server'smasterdatabase (this is probably not a good idea, since it is an internal database for SQL server). - codeapemasternotmaster.dbas in your db URI. - codeape