gpt4 book ai didi

c# - 连接数据库时出错

转载 作者:行者123 更新时间:2023-12-03 08:04:33 25 4
gpt4 key购买 nike

以下代码在执行期间给出错误。

string connectionString = "Data Source=D:\\Base.sdf;Persist Security Info=False";
SqlConnection sqlConnection = new SqlConnection(connectionString))
sqlConnection.Open();

错误是:

A network-related or instance-specific error occured 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 not configured to allow remote connections. (provider:SQL network Interfaces, error: 26 - Error locating Server/Instance Specified)



我尝试使用 SqlCeConnection而不是 SqlConnection,但编译器找不到具有该类的库。

请帮助解决这个问题。
  • 操作系统:Windows 7
  • 工具:Microsoft Visual Studio 2010
  • 语言:C#
  • 最佳答案

    您的数据库是Sql Server精简版之一,必须使用:

    SqlCeConnection sqlConnection = new SqlCeConnection(connectionString);

    从此处下载库 Microsoft SQL Server Compact 4.0
  • 在项目中添加对System.Data.SqlServerCe.dll的引用
  • 使用System.Data.SqlServerCe;
  • 使用指令添加它
  • 使用SqlCeConnection代替SqlConnection
  • 关于c# - 连接数据库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12157209/

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