connect to Azure SQL database via pyodbc

2024/9/22 16:42:27

I use pyodbc to connect to my local SQL database which works withoout problems.

SQLSERVERLOCAL='Driver={SQL Server Native Client 11.0};Server=(localdb)\\v11.0;integrated security = true;DATABASE=eodba;'
cnxn = pyodbc.connect(SQLSERVERLOCAL)   #works

I try the connection to the azure sql database with:

SQLSERVERAZURE='Driver={SQL Server Native Client 10.0};Server=tcp:mydatbase.database.windows.net,1433;Database=mydb;Uid=myuser@myerver;Pwd=mypass;Encrypt=yes;Connection Timeout=30;'
cnxn = pyodbc.connect(SQLSERVERAZURE)   #works not

what gives me the error:

[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')
Answer

Besides the suggestions that provided by meet-bhagdev who recommended to use pymssql dirve that mentioned in link, to resolve the error: Data source name not found and no default driver specified (0) (SQLDriverConnect)') that encountered, please update your connect string as below to see if it works.

conn = pyodbc.connect('DRIVER={SQL Server};SERVER=yoursqlAzureServer.database.windows.net,1433', user='yourName@yoursqlAzureServer', password='Password', database='DBName')

https://en.xdnf.cn/q/71925.html

Related Q&A

Generator function for prime numbers [duplicate]

This question already has answers here:Simple prime number generator in Python(28 answers)Closed 9 years ago.Im trying to write a generator function for printing prime numbers as followsdef getPrimes(n…

`ValueError: too many values to unpack (expected 4)` with `scipy.stats.linregress`

I know that this error message (ValueError: too many values to unpack (expected 4)) appears when more variables are set to values than a function returns. scipy.stats.linregress returns 5 values accord…

Django prefetch_related from foreignkey with manytomanyfield not working

For example, in Django 1.8:class A(models.Model):x = models.BooleanField(default=True)class B(models.Model):y = models.ManyToManyField(A)class C(models.Model):z = models.ForeignKey(A)In this scenario, …

Running SimpleXMLRPCServer in separate thread and shutting down

I have a class that I wish to test via SimpleXMLRPCServer in python. The way I have my unit test set up is that I create a new thread, and start SimpleXMLRPCServer in that. Then I run all the test, and…

Clean Python multiprocess termination dependant on an exit flag

I am attempting to create a program using multiple processes and I would like to cleanly terminate all the spawned processes if errors occur. below Ive wrote out some pseudo type code for what I think …

Any limitations on platform constraints for wheels on PyPI?

Are there any limitations declared anywhere (PEPs or elsewhere) about how broad a scope the Linux wheels uploaded to PyPI should have? Specifically: is it considered acceptable practice to upload li…

Match set of dictionaries. Most elegant solution. Python

Given two lists of dictionaries, new one and old one. Dictionaries represent the same objects in both lists. I need to find differences and produce new list of dictionaries where will be objects from n…

Cookies using Python and Google App Engine

Im developing an app on the Google App Engine and have run into a problem. I want to add a cookie to each user session so that I will be able to differentiate amongst the current users. I want them all…

Matplotlib animations - how to export them to a format to use in a presentation?

So, I learned how to make cute little animations in matplotlib. For example, this:import numpy as np import matplotlib import matplotlib.pyplot as pltplt.ion()fig = plt.figure() ax = fig.add_subplot(…

Where is python interpreter located in virtualenv?

Where is python intrepreter located in virtual environment ? I am making a GUI project and I stuck while finding the python interpreter in my virtual environment.