2017-10-17 2 views
0

J'essaie d'utiliser SQL Server 2016 au lieu de localdb. Lorsque je tente de le changer dans le fichier web.config mssqllocaldb-v13.0 il me donne l'erreur suivante:Modifier la chaîne de connexion dans Entity Framework de localDB vers 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

Que ** ** édition de SQL Server 2016 avez-vous installé? Et avez-vous spécifié un nom d'instance lors de l'installation? Le SQL Server 2016 ** Express ** est installé par défaut en tant que '. \ SQLEXPRESS', tandis que les autres éditions sont généralement installées en tant qu'instances * par défaut, sans nom * (auxquelles vous pouvez accéder en utilisant' .' ou '(local)' comme votre serveur/nom de l'instance) –

+0

Édition Enterprise et n'a pas spécifié quoi que ce soit –

+0

Votre chaîne de connexion devrait donc être quelque chose comme 'Data Source = (local); Initial Catalog = (votre nom de base de données); Sécurité intégrée = SSPI; 'ou quelque chose comme ça - pouvez-vous s'il vous plaît nous montrer (en éditant/mettant à jour votre question) ce que vous utilisez? –

Répondre

1

Vous pouvez lire sur la configuration à MSDN: Entity Framework Config File Settings

Un exemple web.config pourrait être:

<?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