2015-01-10 2 views
-2

안녕하세요, 다음 코드로 데이터베이스에 연결하려고합니다. 하지만 오류 메시지가 표시됩니다.데이터베이스를 열 수 없습니다. 사용자가 로그인하지 못했습니다.

로그인 요청한 데이터베이스 "CPL"을 열 수 없습니다. 로그인에 실패했습니다. 'Dell-PC \ Dell'사용자가 로그인하지 못했습니다.

그것은 전에 잘 작동했다. 있는 Web.Config에서

의 C# 코드

protected void Page_Load(object sender, EventArgs e) 
    { 
     string CurrentDate = DateTime.Today.ToShortDateString(); 
     string CS = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; 
     using (SqlConnection con = new SqlConnection(CS)) 
     { 
      DataTable dtMatchDetails = new DataTable(); 
      string query = "Select MatchTeam1,MatchTeam2 from tblSchedule Where MatchDate =" + CurrentDate; 
      SqlCommand cmd = new SqlCommand(query, con); 
      con.Open(); 
      SqlDataAdapter da = new SqlDataAdapter(cmd); 
      da.Fill(dtMatchDetails); 
      con.Close(); 
      da.Dispose(); 
     } 

연결 문자열은

<connectionStrings> 
<add name="ApplicationServices" 
    connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;User Instance=true;database = CPL" 
    providerName="System.Data.SqlClient=" /> 
</connectionStrings> 
+0

당신은 반드시 연결 문자열은 옳은 있습니까? –

+0

@ SonerGönül 네, 이전에 잘 작동했습니다. – user1295408

+0

오류의 원인은 무엇입니까? 성공적으로 연결하려는 시도와 실패한 연결 시도간에 SQL Server 또는 이와 관련된 다른 항목을 업그레이드 했습니까? 'User Instance = true'없이 연결을 시도하십시오. 또한 공급자 이름에 여분의 심볼'='이 있습니다. –

답변

0

이 연결 문자열이 괜찮다는 것을 의미한다. 사용자와 비밀번호는 정상입니다.

특정 데이터베이스에 대한 액세스 권한을 부여해야합니다.

예를 들어, 관리자 권한으로 SQL 서버에 로그인 한 후 :

USE CPL 
EXEC sp_addrolemember 'db_datareader', '(your user name)' 
관련 문제