2016-07-05 5 views
1

을 열지 못했습니다, 내 PC는 localdb의 V13을 가지고 있으며, 나는 EF 데이터베이스에 연결하려고 할 때, 나는EF6 내가 EF6 간단한 콘솔 응용 프로그램을

{"Cannot open database \"NinjaDomain.DataModel.NinjaContext\" requested by the login. The login failed.\r\nLogin failed for user 'xx\\xx.yy'."} 

이가이 오류를 얻을 의 app.config

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="mssqllocaldb" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 
+0

나는 SQL 서버 로컬 db btw에 대한 관리자입니다. ... –

+0

C : \ WINDOWS \ system32> sqllocaldb.exe를 작성하십시오. 13.0.1100.286에 로컬 데이터베이스를 생성하십시오. –

+0

AppData의 app.config에 연결 문자열을 추가하십시오. –

답변

1

그것은 당신이 그런 식으로 패키지 관리자 콘솔에서 EF가 설치되어 정상적으로 경우도의 App.config가있을 수 있습니다 콘솔 응용 프로그램을 중요하지 않습니다이다 :

install-package entityframework 
,

app.config가 자동으로 프로젝트 파일에 추가됩니다. 당신이 경우에

이 기본 연결 문자열이에게의 app.config이없는 경우 아래

"Data Source=(localdb)\\mssqllocaldb;Initial Catalog=MyConsoleApplication.Program+MyDbContext;Integrated Security=True;MultipleActiveResultSets=True" 

(EF의 V 6.1.3 관련), 난합니다 (의 app.config을 변경 한 하지 당신은 당신의 프로젝트에 추가 할 수 있습니다) 그리고 당신은 그런 '이름'키워드로 DbContext의 생성자에 연결 문자열을 통과해야

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> 
    </startup> 
    <connectionStrings> 
    <add name="DatabaseConnectionString" 
     connectionString="Integrated Security=SSPI; Initial Catalog=UsersDatabase5; Data Source=.\;" providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="mssqllocaldb" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

연결 문자열을 제공하고 있습니다 :

에게

내의 app.config 예에서 정상적인 SQL 서버를 사용하고 있습니다 :

Data Source=(localdb)\\mssqllocaldb; 

또는 당신의 SQL Server 인스턴스 이름 (사용 SSM 또는 명령을 확인합니다

Data Source=.\; 

당신은 변경할 수 있습니다 선).