2013-04-01 1 views
0

안녕하세요, 저는 Windows Forms 프로젝트에서 로컬 SQL Server Compact 데이터베이스 (.sdf)에 연결을 시도하고 있으며이 문제를 오랫동안 겪어 왔습니다. 프로젝트에 대한 데이터 집합을 사용할 수 없으며 모든 쿼리와 연결은 응용 프로그램에 작성됩니다.SDF 로컬 데이터베이스 연결 오류 : 40

System.Data.SqlClient.SqlException

A network-related or instance-specific error occurredwhile 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

코드 :

SqlConnection _Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["restaurant"].ToString()); 
SqlCommand _Command = _Connection.CreateCommand(); 

_Connection.Open(); // <- throws exception 

답변

2

가 (.... 등등 SqlCeConnection, SqlCeCommand과) 다른 namespace SqlServerCe에 포함 된 클래스의 집합을 필요의 SQL Server Compact를 연결하려면

SqlCeConnection _Connection = new SqlCeConnection(ConfigurationManager.ConnectionStrings["restaurant"].ToString()); 
SqlCeCommand _Command = _Connection.CreateCommand(); 
_Connection.Open(); 

물론 위에서 언급 한 클래스가 포함 된 어셈블리를 참조해야합니다.

System.Data.SqlServerCe.dll (ADO.NET provider) 

하고 사용하며 문을

using System.Data.SqlServerCe; 
+0

감사를 추가! 그게 도움이 됐어! – Chris

관련 문제