WPF with local database application
I was about to start but I faced this problemA 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 searched alot to found that the error will be in the connection string
but I'm using the connection string from application settings which done by the wizardusing ( SqlConnection _SqlConnection = new SqlConnection ( Properties . Settings . Default . DatabaseConnectionString ) )
{
_SqlConnection . Open ( ); // <= Error Occurs Here
_SqlConnection . Close ( );
}
Error :
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 correc开发者_C百科t and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
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 (add a reference to System.Data.SqlServerCe).
精彩评论