0

Windows 7 64 비트 PC에 SQL Server 2005, 2008 및 2012가 설치되어 있습니다. 이 필요한 경우 ... 확실하지 SQL 데이터베이스에 연결할 수 없습니다. - C#, VS2012, SQL Server 2012


enter image description here

여기 내 구성 관리자이고, 나는 에이전트가 중지 된 것을 볼 수 없습니다. 크기가 나타 그래서 나는 두 개의 이미지로 그것을 밖으로 분할 한 큰

enter image description here

enter image description here


여기에 VS2012의 데이터베이스 탐색기 창에 표시되는 것입니다. 이

enter image description here

다음

내 코드 언급 한 바와 같이

string selectSql = "select * from Tasks"; 

string connectionString = "Data Source=adamssqlserver;Database=master;Integrated Security=True;"; 

using (var cn = new SqlConnection(connectionString)) 
using (var cmd = new SqlCommand(selectSql, cn)) 
{ 
    cn.Open(); // this is the line that throws the error message. 
    using (var reader = cmd.ExecuteReader()) 
    { 
      //do something 
    } 
} 

의 cn.Open() 인 SQL 서버 2012 데이터베이스입니다; 라인이

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

+0

string connectionString = "데이터 원본 = lpc192 \ adamssqlserver, 데이터베이스 = 마스터, 통합 보안 = True; "; – bummi

답변

2
Data Source=adamssqlserver 

잘못 아래에 표시되는 오류 메시지를 무엇이어야한다 :

Data Source=lpc193\adamssqlserver 

이것은 당신이 연결된 서버 탐색기 화면에서 볼 수 있습니다. 연결 문자열은 "adamssqlserver"라는 컴퓨터를 찾고 데이터베이스는 "lpc193"이라는 컴퓨터의 명명 된 인스턴스이므로 lpc193 \ adamssqlserver로 주소가 지정됩니다.

+0

아! 나는 이전에 그것을 시도 했었지만 단 한 번의 슬래시만으로 ... 그 생각을 포기했다. 이번에는 두 개의 역 슬래시를 사용했는데 이제는 작동합니다! 대단히 감사합니다 !!! – adam

+1

아 맞아, 당신은 @ 기호로 연결 고리 앞에 접두사를 붙이면된다. http://www.dotnetperls.com/string-literal – KingCronus

+0

네, 그게 효과가 있습니다. 팁 주셔서 감사합니다 :) – adam

관련 문제