gpt4 book ai didi

c# - 在连接字符串中设置到数据源的方式

转载 作者:搜寻专家 更新时间:2023-10-30 20:00:06 24 4
gpt4 key购买 nike

我的连接字符串是

string connStr = @"Data Source=(local)\SQLEXPRESS
Initial Catalog=University11;
Integrated Security=True";

但后来我把我的数据库复制到

C:\Users\Чак\Desktop\ботанизм\ООП\coursework.start\CourseWorkFinal\CourseWorkFinal\

并将其设置为连接字符串中的方式

  string connStr = @"Data Source=C:\Users\Чак\Desktop\ботанизм\ООП\coursework.start\CourseWorkFinal\CourseWorkFinal\;
Initial Catalog=University11;
Integrated Security=True";

但在那种情况下我有一个异常(exception)

A network-related or instance-specific error occurred while establishing a connection 
to SQL Server. The server was not found or was not accessible. Verify that the instance
name is correct and that SQL Server is configured to allow remote connections.
(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)

我需要什么正确的连接字符串?

最佳答案

如果这是一个“用户实例”对文件的访问,那么连接字符串更像是:

Data Source=.\SQLEXPRESS;AttachDBFilename=YourPath.mdf;Integrated Security=True;

否则,使用初始目录提供在实例上注册的数据库名称。

关于c# - 在连接字符串中设置到数据源的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8379277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com