1

I am creating an Excel file in C# with SQL Server. I've tried several connection strings, but it keeps saying that it does not recognise my user ID (the ID is valid and can connect directly to SQL with this)

Can you help me, or tell me where is the error that comment?

Below I show the connections I've tried

connectionstring = "Integrated Security = SSPI;Initial Catalog='DATABASENAME'; Data Source=XXX.XXX.X.XX; ";

connectionstring = "SERVER=XXX.XXX.X.XX;DATABASE=DATABASENAME;UID=sa;PASSWORD=pass;";

connectionstring = "Persist Security Info=False;User ID=sa;Password=pass;Initial Catalog=DATABASENAME;Server=XXX.XXX.X.XX";

connectionstring = "Data Source=192.168.0.18;Initial Catalog=DATABASENAME;Persist Security Info=True;User ID=sa;Password=pass";

connectionstring = "Persist Security Info=False;Integrated Security=true;Initial Catalog=DATABASENAME;server=(XXX.XXX.X.XX)";

connectionstring = "Data Source=XXX.XXX.X.XX,1433;Network Library=DBMSSOCN; Initial Catalog=DATABASENAME;User ID=sa;Password=pass";

cnn = new SqlConnection(connectionstring);
6
  • The username is sa and the Password is pass right? And you have tried logging into SQL server using Management studio with those credentials? Commented Jul 31, 2015 at 14:28
  • 4
    1st example @ connectionstrings.com/sql-server Commented Jul 31, 2015 at 14:29
  • Those aren't the credentials, i use these to show the code, but effectively, with my credentials i can enter without any problem. Commented Jul 31, 2015 at 14:31
  • Maybe it's a problem on the server then look at the server logs to see the reason it refuses authentication. Apart from that I doubt anyone here can help you with this. Commented Jul 31, 2015 at 14:32
  • - Alex K, i tried that option but, i keeps saying the same. - Dave3of5, i'll look there Commented Jul 31, 2015 at 14:35

3 Answers 3

3

Here is the sample connection string format

Data Source=[server];Initial Catalog=[databasename];User ID=[sa];Password=[password]

example - named instance

Data Source=localhost;Initial Catalog=master;User ID=sa;Password=sa123

in case of the default instance

Data Source=localhost\sqlexpress;Initial Catalog=master;User ID=sa;Password=sa123

if you are trying to access express version from another machine please refer and replace localhost with ip or machine name.

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

3 Comments

hey if we don't have to provide password in connection string and pooling=false
how can we do it
pooling you will be able to add with ;, for details i think refer this one connectionstrings.com/sql-server this will give you various combinations.
2

Navigate to C:\Windows\System32\odbcad32.exe. Go to the Drivers tab and then check to see which ODBC drivers you have installed on your system.

Then go to this website and follow the links at the top for whichever ODBC driver you have installed on your system. For C# you may or may not need the Driver= buts its usually safe.

This is the connection string which usually works for me in C# asp.net, however:

Server=[SERVER];Database=[DATABASE];Uid=[USER];Pwd=[PASSWORD] 

(note how it is different than yours: Pwd= as opposed to Password=)

1 Comment

thanks, i reviewed that site, but i didn't knew how to see what ODBC driver have
0
"HP\\ADMIN;Initial Catalog = PAY_PROCESSING_GO; User ID=sa; Password=admin@123"

this is my connection string but connection consist Keywords. How to solve this problem

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.