Visual Studio 2008 (C#) with SQL Compact Edition database error: 26

我的梦境 提交于 2020-01-04 04:09:06

问题


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)

I've created a SQL compact database, included it in my application, and can connect to the database fine from other database editors, but within my application im trying

using (SqlConnection con = new SqlConnection(Properties.Settings.Default.DatabaseConnection))
{
    con.Open();
}

the connection string is

Data Source=|DataDirectory|\Database.sdf

I'm stumped, any insight?


回答1:


You're using the wrong type of connection object. SqlConnection is for the grown up SQL server, not for SQL Server Compact.

connectionstrings.com has the connection strings you need. For the connection object itself I believe you need the SqlCeconnection class




回答2:


use SqlCeConnection instead of SqlConnection, include the namespace System.Data.SqlServerCe instead of System.Data.SqlServer.

See this article for an example



来源:https://stackoverflow.com/questions/2124457/visual-studio-2008-c-with-sql-compact-edition-database-error-26

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!