简体   繁体   English

在C#中使用SQL Server身份验证的连接字符串

[英]Connection string using SQL Server authentication in C#

I am creating an Excel file in C# with SQL Server. 我正在使用SQL Server在C#中创建一个Excel文件。 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) 我尝试了几个连接字符串,但一直说它不能识别我的用户ID(该ID有效,并且可以与此直接连接到SQL)

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] 数据源= [服务器];初始目录= [数据库名称];用户ID = [sa];密码= [密码]

example - named instance 示例-命名实例

Data Source=localhost;Initial Catalog=master;User ID=sa;Password=sa123 数据源=本地主机;初始目录=主用户;用户ID = sa;密码= sa123

in case of the default instance 如果是默认实例

Data Source=localhost\\sqlexpress;Initial Catalog=master;User ID=sa;Password=sa123 数据源= localhost \\ sqlexpress;初始目录=主目录;用户ID = sa;密码= sa123

if you are trying to access express version from another machine please refer and replace localhost with ip or machine name. 如果您尝试从另一台计算机访问Express版本,请参考并将localhost替换为ip或计算机名称。

Navigate to C:\\Windows\\System32\\odbcad32.exe . 导航到C:\\Windows\\System32\\odbcad32.exe Go to the Drivers tab and then check to see which ODBC drivers you have installed on your system. 转到“ Drivers选项卡,然后检查系统上已安装了哪些ODBC驱动程序。

Then go to this website and follow the links at the top for whichever ODBC driver you have installed on your system. 然后访问此网站,并按照顶部的链接获取系统上已安装的ODBC驱动程序的信息。 For C# you may or may not need the Driver= buts its usually safe. 对于C#,您可能需要或可能不需要Driver=但是通常它是安全的。

This is the connection string which usually works for me in C# asp.net, however: 这是通常在C#asp.net中对我有用的连接字符串:

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

(note how it is different than yours: Pwd= as opposed to Password= ) (请注意与您的Pwd=有何不同: Pwd=而不是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 如何解决这个问题呢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM