TheDeveloper
TheDeveloper

Reputation: 5

Connection error with PYODBC: function takes at most 1 non-keyword argument

I'm currently trying to learn how to connect a database in SQL Server with Python, using PYODBC, but the problem is that this error keep on appearing and I don't know how to solve it.

import pyodbc as connector
conecction=connector.connect("Driver:{SQL Server Native Client 
11.0};","Server:the name of my server xd;","Database:materiasApp;","Trusted_Connection=yes;")

And I get this error:

 conecction=connector.connect("Driver:{SQL Server Native Client 11.0};","Server:again the name of my 
 server xd;","Database:materiasApp;","Trusted_Connection=yes;")
 TypeError: function takes at most 1 non-keyword argument

Upvotes: 0

Views: 2112

Answers (1)

Parfait
Parfait

Reputation: 107707

For pyodbc, you can either use a single connection string with = for assignment or multiple keyword:

# SINGLE CONNECTION STRING (BROKEN BY LINE)
db = connector.connect("Driver={SQL Server Native Client 11.0};"
                       "Server=name of my server;" 
                       "Database=materiasApp;Trusted_Connection=yes")

# MULTIPLE KEYWORD CONNECTION
db = connector.connect(driver="SQL Server Native Client 11.0",
                       host="name of my server", database="materiasApp",
                       uid="username", pwd="password")

Upvotes: 2

Related Questions