c# - 当我尝试使用 visual c# 连接 SQL Server 时收到此错误消息

标签 c# sql .net sql-server ssl

我正在制作一个连接远程 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/

相关文章:

c# - msbuild 版本 - 必须具备的功能

sql - 如何在 Azure SQL 数据库中存储字典? ( swift )

C# SQL查询异常

c# - 找不到类型或命名空间名称 'async'

C# 是否有 LINQ to HTML 或其他一些好的 .Net HTML 操作 API?

c# - 正则表达式以匹配多个字符串并向后看

c# - JpegBitmapEncoder.Save() 在使用元数据写入图像时抛出异常

mysql - 需要一个通用查询来使用 'EXISTS' 关键字检查行是否存在

sql - 消息 102,级别 15,状态 1,第 24 行 '.' 附近语法错误

.net - 我可以提高此 CSV 导入查询性能吗?