开发者

connecting to local database in wpf application : error 26

开发者 https://www.devze.com 2023-02-28 11:05 出处:网络
WPF with local database application I was about to start but I faced this problem A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was n

WPF with local database application

I was about to start but I faced this problem

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 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 wizard

using ( 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号