1

我正在尝试SqlConnection为 CE (.sdf) 数据库打开一个,但它会引发异常:

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)

我所做的是右键单击 App_Data 文件夹并在那里创建一个数据库。然后我从其属性中复制了连接字符串并将其放在 web.config 中。当我尝试“测试连接”时,它成功了。

除了连接字符串,我没有指定其他属性,如数据源、提供者名称等。

蒂亚!

4

1 回答 1

0

要连接到 SQL Server Compact 数据库文件,您必须使用SqlCeConnection类,而不是 SqlConnection。添加对 System.Data.SqlServerCe.dll ADO.NET 提供程序 DLL 文件的引用以使用 SqlCeConnection 类

于 2013-05-14T13:17:55.397 回答