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);
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.
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=
)
"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
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.