0

I am trying to connect to SQL Server 2008 from Excel VBA using the connection string (ADODB.Connection).

"Driver={SQL Native Client};Data Source=" & Range("Svr").Value & ";Database=" & Range("DB").Value & ";Trusted_Connection=yes"

When I try to open the connection I get this error

Error (-2147467259) Description - [Microsoft][ODBC Driver Manager] Data source name too long

Can some one please provide me a sample

7
  • Are Svr and DB named ranges in your workbook? Commented Oct 5, 2012 at 14:34
  • @Widor...Yes they are in my workbook Commented Oct 5, 2012 at 14:36
  • Can you show us a bit more of the code? Maybe your connection string isn't the problem. It looks like you haven't instantiated the object you are using to make your connection. Commented Oct 5, 2012 at 14:42
  • @JMK .....Yes you are right.....I Misspelled the obj name, but after that when i try to open the connection i get the below error "Error (-2147467259) Description - [Microsoft][ODBC Driver Manager] Data source name too long " Commented Oct 5, 2012 at 14:43
  • Are there any special characters in your data source name? Or is it really long? Commented Oct 5, 2012 at 14:46

1 Answer 1

1

I think the backslash in your connection string is causing your issues, try and escape it like so:

xxxxxxxxxxxx.xxx.xx.xxxxxxxx.xxx\\xxxx01xxx

Also, putting quotes around each value wouldn't hurt:

"Driver={SQL Native Client};Data Source='" & Range("Svr").Value & "';Database='" & Range("DB").Value & "';Trusted_Connection=yes"

Based on this answer.

Sign up to request clarification or add additional context in comments.

Comments

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.