SQL Server How to connect to Local MS SQL Express Edition using Python 3

wz3gfoph  于 2023-03-22  发布在  Python
关注(0)|答案(2)|浏览(190)

I am trying to connect to local MS SQL Express Edition. I am using canopy for Python editing.

Code:

import pymssql

conn = pymssql.connect(server='******\SQLEXPRESS',user = 'MEA\*****',password='*****',database='BSEG')

cursor = conn.cursor()

cursor.execute('SELECT * FROM Table')
print(cursor.fetchone())

conn.close()

Error::

pymssql.pyx in pymssql.connect (pymssql.c:10734)()

_mssql.pyx in _mssql.connect (_mssql.c:21821)()

_mssql.pyx in _mssql.MSSQLConnection.init (_mssql.c:5917)()

ValueError: too many values to unpack (expected 2)

tjjdgumg

tjjdgumg1#

user = 'MEA\*****',password='*****'

MEA\***** seems to be Windows login , in this case you shouldn't pass in any password, your user name is enough, but you also should use Integrated security or Trusted parameter in your connection string

It should be smth like this:

server='******\SQLEXPRESS',Trusted_Connection=yes,database='BSEG'
hivapdat

hivapdat2#

In my local machine I only have the sql express instance, then after some tryes I get that server can be just ".". the user that I am using is sa

相关问题