2017-10-17 76 views
0

我正在嘗試使用SQL Server 2016而不是localdb。當我嘗試從mssqllocaldb在web.config文件來改變它v13.0 它給了我下面的錯誤:將實體框架中的連接字符串從localDB更改爲Microsoft SQL Server

An exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll but was not handled in user code.

Additional information: 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

+1

什麼**版的SQL Server 2016 **是否安裝?你是否在安裝過程中指定了一個實例名稱? SQL Server 2016 ** Express **默認安裝爲'。\ SQLEXPRESS',而其他版本通常安裝爲* default,unnamed *實例(您可以使用'.'或'(local)'作爲您的訪問服務器/實例名稱) –

+0

企業版,並沒有指定任何東西 –

+0

那麼你的連接字符串應該是'Data Source =(local);初始目錄=(你的數據庫名稱);集成安全= SSPI;'或類似的東西 - 你能告訴我們(通過編輯/更新你的問題)你正在使用的是什麼? –

回答

1

您可以在MSDN: Entity Framework Config File Settings

一個例子web.config中讀取有關配置可以是:

<?xml version="1.0"?> 
<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> 

    <connectionStrings> 
    <add name="MyConnectionString" connectionString="Data Source=MySqlServerInstance;Initial Catalog=MyDatabase;Integrated Security=True" 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> 
-1

[IIExpress] [1]

I believe since .netFramework4 IIExpress has been the default Db. 
Prior to that I believe localIS was. The Image below shows how to change 
to IIExpress if required. This tutorial will explain it better. 

https://www.youtube.com/watch?v=k5RKfOEpOGk&index=9&list=PL6n9fhu94yhXQS_p1i-HLIftB9Y7Vnxlo

[1]: https://i.stack.imgur.com/yP3cj.png 

Here is a very good tutorial to help write the ADO.net code 

https://www.youtube.com/watch?v=aoFDyt8oG0k&list=PL6n9fhu94yhX5dzHunAI2t4kE0kOuv4D7

相關問題