IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET MVC Discussion :

visual studio créer une base de données à partir du modèle


Sujet :

ASP.NET MVC

  1. #1
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut visual studio créer une base de données à partir du modèle
    Bonjour à tous,

    Pourriez vous m'aider? voici mon problème j'utilise une application développer par une entreprise externe, mais je n'ai pas la base de données. J'ai par contre els sources mais sans la base je ne peux pas la lancer et donc la modifier. J'ai donc penser à créer la table à partir du model avec la technique du model first mais j'ai les erreurs suivantes:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
       at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
       at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
       at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    ClientConnectionId:00000000-0000-0000-0000-000000000000
    Error Number:-1,State:0,Class:20
    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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    Les commandes que j'ai utilisé:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Enable-Migrations -ContextTypeName  Massa.Admin.Models.Identity.ApplicationDbContext
    Checking if the context targets an existing database...
    Code First Migrations enabled for project Continental.Massa.Admin.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    add-migration Initial
    Re-scaffolding migration 'Initial'.
    et enfin
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    PM> update-database
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
       at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
       at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
       at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    ClientConnectionId:00000000-0000-0000-0000-000000000000
    Error Number:-1,State:0,Class:20
    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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    PM> update-database 
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
       at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
       at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
       at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
       at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
       at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
       at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
       at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
       at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
       at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    ClientConnectionId:00000000-0000-0000-0000-000000000000
    Error Number:-1,State:0,Class:20
    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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

  2. #2
    Rédacteur
    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Billets dans le blog
    121
    Par défaut
    Le message est assez explicite :

    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.
    Entity Framework ne parvient pas à établir une connexion avec ton serveur SQL Server. Vérifie tes paramètres d’accès à la base de données dans ta chaîne de connexion.
    Vous souhaitez participer aux rubriques .NET ? Contactez-moi

    Si déboguer est l’art de corriger les bugs, alors programmer est l’art d’en faire
    Mon blog, Mes articles, Me suivre sur Twitter
    En posant correctement votre problème, on trouve la moitié de la solution

  3. #3
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Merci de votre réponse, je dois modifier la chaine de connection comment faire pour que cela fonctionne?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <connectionStrings>
        <add name="CONTI_MASSAEntities" connectionString="metadata=res://*/DataModels.DB.csdl|res://*/DataModels.DB.ssdl|res://*/DataModels.DB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=mw-sql2008;initial catalog=CONTI_MASSA;persist security info=True;user id=id;password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>

  4. #4
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Je pense j'ai un problème avec sqlserveur
    Nom : bug.PNG
Affichages : 635
Taille : 125,1 Ko
    il ne trouve pas le serveur dans la liste server name j'ai essayé d'entrer CL31072G ou (local)/SQLEXPRESS MAIS cela ne fonctionne pas.

  5. #5
    Rédacteur
    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Billets dans le blog
    121
    Par défaut
    La liste déroulante Server Name permet de sélectionner dans une liste contenant tous les serveurs détectés. Si tu as un serveur de base de données sur ton poste, il devrait en principe s'afficher dans cette liste.

    As-tu une instance de SQL Server installé et qui s'exécute sur ton poste ? Peux-tu t y connecter en utiliser SQL Server Managment Studio ?

    Par ailleurs, cette connexion permettra juste d'accéder à ton instance de SQL Server à partir de l'explorateur de serveurs de Visual Studio. Ca ne résout pas pour autant ton problème.

    La chaine de connexion pour ton instance SQL devrait en principe se trouver dans le fichier Web.config qui est à la racine de ton projet. tu devrais avoir les balises suivantes :

    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    <connectionStrings><add name="" connectionString="" providerName="" />
    </connectionStrings>

    Il suffira juste de l'éditer pour renseigner les informations permettant de se connecter à ton instance de SQL Server.
    Vous souhaitez participer aux rubriques .NET ? Contactez-moi

    Si déboguer est l’art de corriger les bugs, alors programmer est l’art d’en faire
    Mon blog, Mes articles, Me suivre sur Twitter
    En posant correctement votre problème, on trouve la moitié de la solution

  6. #6
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Merci, j'ai bien sqlserver

    Nom : sqlserver.PNG
Affichages : 648
Taille : 81,1 Ko

    je prend la connection string du serveur dans les attributs et je m'est dans mon webconfig

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
       <add name="ConnectionStringName" providerName="System.Data.SqlClient"  connectionString="Data Source=(localdb)\Projects;
                              Initial Catalog=master;
                              Integrated Security=False;
                              MultipleActiveResultSets=True" />
    mais quand je fais un update-database même problème:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    Pourtant le serveur existe bien.

    Merci de votre aide.

  7. #7
    Rédacteur
    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Billets dans le blog
    121
    Par défaut
    As-tu renseigner le bon nom de ta chaîne de connexion (ConnectionStringName) dans ton DbContext ?

    La chaîne de connexion que tu viens de définir c'est pour LocalDB. Une s'agit d'une déclinaison de SQL Server pour les développeurs permettant à ces derniers de s'affranchir d'une instance de SQL Server avec les configurations liées.

    J’émets quelques réserves sur ton Data Source=(localdb)\Projects. (localdb)\Projects est une instance réservée aux Data Tools SQL Server. De plus, tu utilises la base de données master qui est réservée.

    Tu peux regarder cet article. Il devrait t'aider pour ta chaîne de connexion.
    Vous souhaitez participer aux rubriques .NET ? Contactez-moi

    Si déboguer est l’art de corriger les bugs, alors programmer est l’art d’en faire
    Mon blog, Mes articles, Me suivre sur Twitter
    En posant correctement votre problème, on trouve la moitié de la solution

  8. #8
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    Merci, ma chaine de connexion est correcte voici la capture de ma base de donnée conti_massa que j'ai créer sur le serveur de visualstudio

    Nom : database.png
Affichages : 416
Taille : 2,2 Ko

    Le server local est bien (localdb)\Projects je ne peux pas le changer de toute façon, j'ai changé le nom de la base de données.
    Ma chaîne de connexion récupérer depuis les attributs de ma base de données

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     <connectionStrings>
        <add name="ConnectionStringName" providerName="System.Data.SqlClient" connectionString="Data Source=(localdb)\Projects;Initial Catalog=CONTI_MASSA;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" />
    </connectionStrings>
    quand je regarde mon répertoire de migration j'ai bien la data :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
        using System;
        using System.Data.Entity.Migrations;
     
        public partial class Initial : DbMigration
        {
            public override void Up()
            {
                CreateTable(
                    "dbo.AspNetRoles",
                    c => new
                        {
                            Id = c.String(nullable: false, maxLength: 128),
                            Name = c.String(nullable: false, maxLength: 256),
                        })
                    .PrimaryKey(t => t.Id)
                    .Index(t => t.Name, unique: true, name: "RoleNameIndex");
     
                CreateTable(
                    "dbo.AspNetUserRoles",
                    c => new
                        {
                            UserId = c.String(nullable: false, maxLength: 128),
                            RoleId = c.String(nullable: false, maxLength: 128),
                        })
                    .PrimaryKey(t => new { t.UserId, t.RoleId })
                    .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true)
                    .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                    .Index(t => t.UserId)
                    .Index(t => t.RoleId);
     
                CreateTable(
                    "dbo.AspNetUsers",
                    c => new
                        {
                            Id = c.String(nullable: false, maxLength: 128),
                            Email = c.String(maxLength: 256),
                            EmailConfirmed = c.Boolean(nullable: false),
                            PasswordHash = c.String(),
                            SecurityStamp = c.String(),
                            PhoneNumber = c.String(),
                            PhoneNumberConfirmed = c.Boolean(nullable: false),
                            TwoFactorEnabled = c.Boolean(nullable: false),
                            LockoutEndDateUtc = c.DateTime(),
                            LockoutEnabled = c.Boolean(nullable: false),
                            AccessFailedCount = c.Int(nullable: false),
                            UserName = c.String(nullable: false, maxLength: 256),
                        })
                    .PrimaryKey(t => t.Id)
                    .Index(t => t.UserName, unique: true, name: "UserNameIndex");
     
                CreateTable(
                    "dbo.AspNetUserClaims",
                    c => new
                        {
                            Id = c.Int(nullable: false, identity: true),
                            UserId = c.String(nullable: false, maxLength: 128),
                            ClaimType = c.String(),
                            ClaimValue = c.String(),
                        })
                    .PrimaryKey(t => t.Id)
                    .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                    .Index(t => t.UserId);
     
                CreateTable(
                    "dbo.AspNetUserLogins",
                    c => new
                        {
                            LoginProvider = c.String(nullable: false, maxLength: 128),
                            ProviderKey = c.String(nullable: false, maxLength: 128),
                            UserId = c.String(nullable: false, maxLength: 128),
                        })
                    .PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
                    .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                    .Index(t => t.UserId);
     
            }
     
            public override void Down()
            {
                DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers");
                DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers");
                DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers");
                DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
                DropIndex("dbo.AspNetUserLogins", new[] { "UserId" });
                DropIndex("dbo.AspNetUserClaims", new[] { "UserId" });
                DropIndex("dbo.AspNetUsers", "UserNameIndex");
                DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" });
                DropIndex("dbo.AspNetUserRoles", new[] { "UserId" });
                DropIndex("dbo.AspNetRoles", "RoleNameIndex");
                DropTable("dbo.AspNetUserLogins");
                DropTable("dbo.AspNetUserClaims");
                DropTable("dbo.AspNetUsers");
                DropTable("dbo.AspNetUserRoles");
                DropTable("dbo.AspNetRoles");
            }
        }
    J'ai installé sql server managment studio et je ne le voit pas, j'ai pu voir sur le net https://forums.asp.net/t/1227004.asp...+Visual+Studio une commande pour réinitialiser par contre je ne trouve pas l'invite de commande dans visual studio?

    Merci beaucoup pour votre aide.

  9. #9
    Rédacteur
    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Billets dans le blog
    121
    Par défaut
    Citation Envoyé par kevin254kl Voir le message

    Le server local est bien (localdb)\Projects je ne peux pas le changer de toute façon, j'ai changé le nom de la base de données.
    Ma chaîne de connexion récupérer depuis les attributs de ma base de données
    Pourquoi tu ne peux pas le changer ? Tu utilises quelle version d'Entity Framework ?


    Citation Envoyé par kevin254kl Voir le message
    J'ai installé sql server managment studio et je ne le voit pas, j'ai pu voir sur le net https://forums.asp.net/t/1227004.asp...+Visual+Studio une commande pour réinitialiser par contre je ne trouve pas l'invite de commande dans visual studio?
    Tu dois utiliser la console du gestionnaire de package NuGet, qui est un invite de commande PowerShell intégré à Visual Studio. Pour l'afficher, tu vas sur le menu Outils, puis sur Gestionnaire de package Nuget, puis sur Console du gestionnaire de package.
    Vous souhaitez participer aux rubriques .NET ? Contactez-moi

    Si déboguer est l’art de corriger les bugs, alors programmer est l’art d’en faire
    Mon blog, Mes articles, Me suivre sur Twitter
    En posant correctement votre problème, on trouve la moitié de la solution

  10. #10
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    J'ai un peux avancée

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
      <connectionStrings>
        <add name="CONTI_MASSAEntities" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=CONTI_MASSA;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient" />
      </connectionStrings>
    Quand je fais le code first :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    PM> Add-Migration Initial
    Scaffolding migration 'Initial'.
    The Designer Code for this migration file includes a snapshot of your current Code First model. This snapshot is used to calculate the changes to your model when you scaffold the next migration. If you make additional changes to your model that you want to include in this migration, then you can re-scaffold it by running 'Add-Migration Initial' again.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Update-Database -TargetMigration:"Initial"
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    Reverting migrations: [201611290859293_Initial2, 201611290857411_Initial1, 201611290855090_Migrations].
    Reverting explicit migration: 201611290859293_Initial2.
    Reverting explicit migration: 201611290857411_Initial1.
    Reverting explicit migration: 201611290855090_Migrations.
    je ne comprend pas si cela à fonctionné ou pas?
    Je démarre l'appli qui me renvoi au login et mot de passe qui sont en dure dans le code mais après clique sur le bouton j'ai

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    An exception of type 'System.Data.Entity.Infrastructure.UnintentionalCodeFirstException' occurred in Continental.Massa.Admin.dll but was not handled in user code
     
    Additional information: The context is being used in Code First mode with code that was generated from an EDMX file for either Database First or Model First development.  This will not work correctly. To fix this problem do not remove the line of code that throws this exception. If you wish to use Database First or Model First, then make sure that the Entity Framework connection string is included in the app.config or web.config of the start-up project. If you are creating your own DbConnection, then make sure that it is an EntityConnection and not some other type of DbConnection, and that you pass it to one of the base DbContext constructors that take a DbConnection. To learn more about Code First, Database First, and Model First see the Entity Framework documentation here:

  11. #11
    Rédacteur
    Avatar de Hinault Romaric
    Homme Profil pro
    Consultant
    Inscrit en
    Janvier 2007
    Messages
    4 570
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Consultant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2007
    Messages : 4 570
    Billets dans le blog
    121
    Par défaut
    Je crois avoir une idée de la source du problème. Est ce que ton model EF et ton IU sont des projets séparés ? Si oui, peux-tu vérifier si le Web.config du projet de ton IU a la chaine de connexion.
    Vous souhaitez participer aux rubriques .NET ? Contactez-moi

    Si déboguer est l’art de corriger les bugs, alors programmer est l’art d’en faire
    Mon blog, Mes articles, Me suivre sur Twitter
    En posant correctement votre problème, on trouve la moitié de la solution

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Débutant] Visual studio, créer une base de données
    Par Merlo dans le forum VB.NET
    Réponses: 11
    Dernier message: 15/09/2016, 07h06
  2. Créer une base de données à partir d'un fichier .dmp
    Par funboard dans le forum Import/Export
    Réponses: 1
    Dernier message: 08/12/2008, 17h14
  3. Créer une base de données à partir d'un questionnaire Excel
    Par Pierre Jean-Pierre dans le forum Excel
    Réponses: 1
    Dernier message: 20/06/2008, 15h16
  4. créer une base de donnée à partir d'un script
    Par illegalsene dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 26/08/2005, 14h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo