我正在尝试为CE(.sdf)数据库打开SqlConnection
,但它会引发异常:
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中。当我尝试“测试连接”时,它会成功。
除连接字符串外,我没有指定其他属性,如数据源,提供程序名称等。
TIA!
答案 0 :(得分:0)
要连接到SQL Server Compact数据库文件,必须使用 SqlCeConnection 类,而不是SqlConnection。添加对System.Data.SqlServerCe.dll ADO.NET提供程序DLL文件的引用以使用SqlCeConnection类