P
P
Prepod212019-12-08 12:14:02
Python
Prepod21, 2019-12-08 12:14:02

How to properly configure MS SQL and connect via pyodbc?

1) Installed MS SQL Server 2014 Express, created a database in Managmtnt Studio, added user user with password "1" to "Login Names".
Enabled TCP connection, port 1433. In the Windows firewall, added the port and MSSQL to exceptions. Installed ODBC plugin for MSSQL.
2) in python I execute the script:

import pyodbc

con = pyodbc.connect('DRIVER={SQL Server};SERVER=127.0.0.1;PORT=1433;DATABASE=TestDB;UID=user;PWD=1')
cursor = con.cursor()
cursor.execute("select ID, NAME from USERS")
row = cursor.fetchone()
if row:
    print(row)

getting error:
pyodbc.ProgrammingError: ('42000', '[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open database 'TestDB' requested by login. Login failed. (4060) (SQLDriverConnect);
What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Prepod21, 2019-12-08
@Prepod21

After solving the login problem, I got the following error:
Permission denied "SELECT" on object "USERS" of database "TestDB", schema "dbo"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question