我正在制作一个连接远程 SQL Server 的简单应用程序。
这是连接字符串。
string connectionString = "Data Source=ip address;Initial Catalog=TELMAR;User ID=sa;Password=password;Trusted_Connection=false;encrypt=false";
如果我将 encrypt 设置为 true。我收到此错误:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
如果我将加密设置为 false。我收到此错误:
Cannot open database "TELMAR" requested by the login. The login failed. Login failed for user 'sa'.
当我尝试使用 SQL Server Management Studio 连接到服务器时,我可以毫无问题地连接。
我不知道为什么我无法使用 Visual C# 连接到 SQL Server。
我还在我的计算机和服务器上启用了 TCP\IP 和命名管道。
谁能帮帮我?
最佳答案
尝试将连接字符串更改为这种格式
<add name="TELMAR" connectionString="Data Source = ip adress;Initial Catalog=TELMAR;MultipleActiveResultSets=true; User Id = sa; Password = password providerName="System.Data.SqlClient"/>
并且在program.cs中可以通过这种方式初始化连接字符串
string conStr = ConfigurationManager.ConnectionStrings["TELMAR"].ConnectionString;
关于c# - 当我尝试使用 visual c# 连接 SQL Server 时收到此错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28770420/