首页 > 解决方案 > 在客户端机器上部署 Winforms 应用程序

问题描述

我使用实体框架创建了一个带有本地数据库的 Windows 的 Winforms 应用程序。

在我的电脑上,应用程序运行良好;但是当我SETUP在另一台机器上创建并安装它时,我收到以下错误:

有关调用即时调试
(JIT) 而不是此对话框的详细信息,请参阅本文末尾。

************** 异常文本 **************

System.Data.Entity.Core.EntityException:基础提供程序在打开时失败。
System.Data.SqlClient.SqlException:建立与 SQL Server 的连接时发生网络相关或特定于实例的错误。服务器找不到或无法访问。验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供者:SQL 网络接口,错误:26 - 定位指定服务器/实例时出错)

到 System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity 标识、sqlConnectionString connectionOptions、SqlCredential 凭据、对象 providerInfo、newPassword 字符串、SecureString newSecurePassword、布尔重定向用户实例、sqlConnectionString userConnectionOptions、SessionData reconnectSessionData、DbConnectionPool 池 accessToken 字符串、布尔 applyTransientFaultHandling、SqlAuthenticationProviderManager sqlAuthProviderManager)
在 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项,DbConnectionPoolKey poolKey,对象 poolGroupProviderInfo,DbConnectionPool 池,DbConnection owningConnection,DbConnectionOptions userOptions)
在 System.Data.ProviderBase.DbConnectionPool.CreateObject (
DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
在 System.Data. .ProviderBase.DbConnectionPool.UserCreateRequest (DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)

这是我的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>

标签: c#.netvisual-studiowinforms

解决方案


这是未连接的 SQL Server 的问题。

您可能会发现以下解决方案是正确的:

  1. 您需要启动 SQL Server 服务

    在 Windows 中打开运行,输入services.msc,然后找到 SQL Server 并启动服务器,然后再次检查您的应用程序

  2. 其次是检查您的 SQL Server 登录凭据是否对新机器有效

希望你找到解决办法


推荐阅读