2

If this has been asked, I apologize in advance, I couldn't find the right answer, although I've found similar questions.

I'm trying to connect to a SQL Server 2008 DB by using it's IP / Port using trusted connection.

One additional point of complexity is: The database is outside of the US and usually we log in via Citrix. After logging into citrix, it uses our windows credentials (not sure if that impacts the issue).

I have tried several different types of connection strings

Driver=SQL Server
Driver=SQL Native Client
Driver=SQL Server Native Client 10.0

I've also tried differen't formats of including the port, as well as messing with the Network Library when using the IP route.

I was hoping someone could help me understand 2 things.

1) (Most importantly) How do I figure out how to properly connect without simple trial and error. I tried checking connectionstrings.com but that didn't really help all that much. I haven't been able to find anything online.

2) If someone can help me out with connection string.

Here's an example of what I'm doing:

cn = pyodbc.connect(r'DRIVER={SQL Native Client};Server=1.1.3.4,1234;Network    Library=DBMSSOCN;Initial Catalog=Test;UID=DOM\me;Pwd=pass')

Any help/guidance is much appreciated.

2 Answers 2

10

You don't need to specify a user or password if you want to use a trusted connection, instead use the paramater Trusted_Connection=yes. See here for the documentation.

Something like this has worked for me in the past:

cn = pyodbc.connect('DRIVER={SQL Native Client};
                     Server=1.1.3.4; DATABASE=mydb; 
                     Trusted_Connection=yes;')
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Matti, apologies for not getting back sooner. I've been swamped with issues and haven't had a chance to come back to the code just yet. I'll post as soon as I have a moment. Thank you for your time, even looking into it.
Another reason it might not be working is the format of the IP address format - have you tried using a colon instead of a comma to separate the port number?
-5

Find here some explanation, relevant links, and sample code.

1 Comment

You generally don't want to provide a link as an SO answer, because most of the time the link will be outdated and not working in future. This actually happens with your link. It does not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.