简体   繁体   English

SQL数据库无法在第二台PC上初始化,并显示消息“底层提供程序无法打开”

[英]SQL database failing to initialise on second PC with message 'The underlying provider failed to open'

I have a VSExpress 2013 solution (with 3 projects) with Entity Framework (ADO.NET) accessing a SQL Server database. 我有一个VSExpress 2013解决方案(包含3个项目),其中的Entity Framework(ADO.NET)访问SQL Server数据库。 I am able to publish my project to the original source PC, and it works as expected, but attempting to install on a second PC via CD fails. 我可以将项目发布到原始源PC,并且可以按预期工作,但是尝试通过CD在第二台PC上安装失败。 The installation is failing to instantiate or create the necessary database files on the local SQL Server (localDB), although SQL Server Express (LocalDB) installs correctly. 尽管SQL Server Express(LocalDB)正确安装,但安装无法在本地SQL Server(localDB)上实例化或创建必要的数据库文件。

I tried adding the line: 我尝试添加以下行:

Database.SetInitializer<PMMEntities>(new CreateDatabaseIfNotExists<PMMEntities>());

to MainWindow() on start-up to initialise the database. 启动时转到MainWindow()以初始化数据库。 However, I still get the following error on running the application on the other PC: 但是,在另一台PC上运行该应用程序时,仍然出现以下错误:

A network-related or instance specific error occurred while establishing a connection to SQL Server. 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible. 服务器未找到或无法访问。 Verify that the the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces. error:26 - Error locating Server/Instance Specified) (提供者:SQL网络接口。错误:26-查找指定的服务器/实例时出错)

The connection string in app.config is (note that I am not trying to access a shared database on a network, and each installation on another PC must create and run its own local DB): app.config的连接字符串为(请注意,我没有尝试访问网络上的共享数据库,并且另一台PC上的每个安装都必须创建并运行自己的本地DB):

<connectionStrings>
    <add name="PMMEntities" 
         connectionString="metadata=res://*/PMMData.csdl|res://*/PMMData.ssdl|res://*/PMMData.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=PMM;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings>

I am using ClickOnce settings. 我正在使用ClickOnce设置。 What do I need to do to achieve effective installation on other PCs so that they will instantiate a new database on first execution? 我需要怎么做才能在其他PC上有效安装,以便它们在首次执行时实例化新数据库?

听起来好像SQL Express尚未安装在第二台PC上,或者正在使用其他实例名称安装,或者在ClickOnce部署期间安装失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM