Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 本地数据库的连接字符串不工作_C#_Sql_.net_Connection String - Fatal编程技术网

C# 本地数据库的连接字符串不工作

C# 本地数据库的连接字符串不工作,c#,sql,.net,connection-string,C#,Sql,.net,Connection String,我在SQL Server Management studio上的本地计算机上有一个数据库。 数据库连接信息如下所示。 在我的c#应用程序中,我有一个连接到该数据库的连接字符串。尽管我说我的连接字符串不正确,但还是出现了一个错误。我试过很多不同的方法 这是我连接数据库的功能 public virtual void openConnection() { con = new SqlConnection(); con.ConnectionString =

我在SQL Server Management studio上的本地计算机上有一个数据库。

数据库连接信息如下所示。

在我的c#应用程序中,我有一个连接到该数据库的连接字符串。尽管我说我的连接字符串不正确,但还是出现了一个错误。我试过很多不同的方法

这是我连接数据库的功能

  public virtual void openConnection()
    {
        con = new SqlConnection();
        con.ConnectionString = "Server=DESKTOP-8UDMQUI\\WILLIAMSQL;Initial Catalog=team3db;TrustServerCertificate=true;";

        try
        {
            con.Open();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }
我在服务器名称中有两个\是因为当我只有一个时,它下面有一条红色的曲线,这在visual studio上给我带来了一个错误


我的连接字符串应该是什么?注意,此数据库上没有密码。

替换
TrustServerCertificate=true具有集成安全性=true

替换
TrustServerCertificate=true集成安全=true

。然后使用
con.ConnectionString=“Server=DESKTOP-8UDMQUI\\WILLIAMSQL;Initial Catalog=team3db;TrustedConnection=true;”如果要在分析中使用windows身份验证。然后使用
con.ConnectionString=“Server=DESKTOP-8UDMQUI\\WILLIAMSQL;Initial Catalog=team3db;TrustedConnection=true;”TrustServerCertificate关键字仅在使用有效证书连接到SQL Server实例时有效。TrustServerCertificate关键字仅在使用有效证书连接到SQL Server实例时有效。