简体   繁体   中英

Can't connect my python script to SQL database that's on VM

I'm using VirtualBox as my VM, and on it I have SQL server, and my python script runs on local host.

My connection string looks like this engine = create_engine('mssql+pyodbc://'+username+':'+password+'@127.0.0.1:1433/'+database+'?driver=SQL+Server+Native+Client+11.0')

I'm getting "Data source name not found and default driver not specified" error. I've tried a lot of stuff, and I can't make it work still. Thanks

If you running Python script on System
The pythons script gets connected to localhost server of the system not Virtual Box

The problem was in database drivers. I worked on a pc with SQL Server Native Client 11.0 driver, but I didn't have it on the pc where I was deploying the script and on which the VM was on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM