0

I created a Winforms application for Windows with local database using Entity Framework.

On my pc the application works fine; but when I created SETUP and install it on another machine, I get the following error:

See the end of this post for details on invoking debugging
just-in-time (JIT) instead of this dialog.

************** Exception text **************

System.Data.Entity.Core.EntityException: The underlying provider failed on Open.
System.Data.SqlClient.SqlException: A network related or instance specific error occurred while establishing a connection to SQL Server. The server cannot be found or is 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 the specified server / instance)

to System.Data.SqlClient.SqlInternalConnectionTds..ctor (DbConnectionPoolIdentity identity, sqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, newPassword String, SecureString newSecurePassword, Boolean redirectedUserInstance, sqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool accessToken String, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
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)

This is my app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework" requirePermission="false" />
  </configSections>
    
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
    
  <connectionStrings>
      <add name="Db_EleveBookEntities" 
           connectionString="metadata=res://*/EntityModelEB3.csdl|res://*/EntityModelEB3.ssdl|res://*/EntityModelEB3.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\MSSQLLocalDB;attachdbfilename= |DataDirectory|\EleveBookLocaleDB3.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
           providerName="System.Data.EntityClient" />
  </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>
    
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Fozzy.Object" publicKeyToken="da510636ee0727d5" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.1.5585.19816" newVersion="1.1.5585.19816" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mir pekiro
  • 85
  • 7
  • 1
    The error explicitly states that *the Server cannot be found*. Did you install a database Server? – Jimi Feb 03 '21 at 10:29
  • Your app is using SQL Server Express LocalDB, did you install that? Does the `EleveBookLocaleDB3.mdf` file also exist in the data directory of the deployed application? – DavidG Feb 03 '21 at 10:31
  • https://stackoverflow.com/questions/18271301/entity-framework-the-underlying-provider-failed-on-open/36732048 – Aristos Feb 03 '21 at 10:35
  • If you are using LocalDB then you still need to install some drivers before it will work. – GuidoG Feb 03 '21 at 15:24
  • I think [this](https://learn.microsoft.com/en-us/sql/connect/oledb/features/oledb-driver-for-sql-server-support-for-localdb?view=sql-server-ver15) might be usefull for you – GuidoG Feb 03 '21 at 15:26

1 Answers1

0

This is an issue with SQL Server which is not connected.

There are following solution you may find correct:

  1. You need to start SQL Server service

    Open run in Windows, type in services.msc, then find SQL Server and start the server and then check again your application

  2. Second is check is your login credentials for SQL Server is valid for new machine

Hope you find solution

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Wajid
  • 593
  • 3
  • 11
  • From what I can tell the OP is using LocalDB. That means there is no SQL Server Service he needs to start. The problem will probably be that he did not install the drivers for LocalDB – GuidoG Feb 03 '21 at 15:24