0
votes

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>
1
The error explicitly states that the Server cannot be found. Did you install a database Server?Jimi
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
If you are using LocalDB then you still need to install some drivers before it will work.GuidoG
I think this might be usefull for youGuidoG

1 Answers

0
votes

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