我正在使用SQL Server在C#中创建Excel文件。我已经尝试了几个连接字符串,但它一直说它无法识别我的用户ID(该ID有效并且可以直接连接到SQL)
你能帮助我,还是告诉我评论的错误在哪里?
下面我展示了我尝试过的关联
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);
答案 0 :(得分:2)
以下是示例连接字符串格式
Data Source = [server]; Initial Catalog = [databasename]; User ID = [sa]; Password = [password]
示例 - 命名实例
Data Source = localhost; Initial Catalog = master; User ID = sa; Password = sa123
如果是默认实例
Data Source = localhost \ sqlexpress; Initial Catalog = master; User ID = sa; Password = sa123
如果您尝试从其他计算机访问快速版本,请refer并将ip替换为本地主机名。
答案 1 :(得分:1)
导航至C:\Windows\System32\odbcad32.exe
。转到Drivers
选项卡,然后检查您的系统上安装了哪些ODBC驱动程序。
然后转到this website并按照顶部的链接查看您在系统上安装的任何ODBC驱动程序。对于C#,您可能需要或不需要Driver=
但通常是安全的。
这是连接字符串,它通常适用于C#asp.net,但是:
Server=[SERVER];Database=[DATABASE];Uid=[USER];Pwd=[PASSWORD]
(请注意它与您的不同之处:Pwd=
而不是Password=
)
答案 2 :(得分:0)
"HP\\ADMIN;Initial Catalog = PAY_PROCESSING_GO; User ID=sa; Password=admin@123"
这是我的连接字符串,但连接包含关键字。如何解决这个问题