我可以连接到的LocalDB MDF文件的计算机上从正在Web服务器上运行一个Web应用程序? [英] Can I connect to LocalDB MDF file on computer from a web app that is being run on a web server?

查看:187
本文介绍了我可以连接到的LocalDB MDF文件的计算机上从正在Web服务器上运行一个Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发,即使用Visual Studio,当其内置的IIS防爆preSS情况下,我已经建立了我的web应用程序使用的LocalDB,与位于目录我的电脑,但没有对数据的MDF文件项目目录里面,如C:\\ MyAppData \\ MyAppData.mdf,而不是C:[...] \\ MyAppProject \\ App_Data文件\\ MyAppData.mdf

In development, i.e., when using Visual Studio and its built-in IIS Express instance, I have set up my web app to use LocalDB, with the data MDF file located in a directory on my computer but not inside the project directory, e.g., "C:\MyAppData\MyAppData.mdf", not "C:[...]\MyAppProject\App_Data\MyAppData.mdf."

这是使用Visual Studio / IIS防爆preSS时工作得很好,和所使用的连接字符串看起来是这样的:

This is working just fine when using Visual Studio/IIS Express, and the connection string being used looks something like this:

<add name="MyAppEntities" connectionString="metadata=res://*/MyAppModel.MyAppModel.csdl|res://*/MyAppModel.MyAppModel.ssdl|res://*/MyAppModel.MyAppModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\v11.0;attachdbfilename=C:\MyAppData\MyAppData.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

我的问题是,当我部署应用程序来开发Web服务器,是有可能,应用程序可以连接到托管在我的电脑上相同的MDF文件?如果是这样,怎么样?如果不是,为什么不呢?请注意,我不是发布MDF文件到开发网络服务器:我试图从正在Web服务器上运行的应用程序访问我的计算机上的MDF文件

My question is, after I deploy the app to a development web server, is it possible that the app can connect to that same MDF file hosted on my computer? If so, how? If not, why not? Note that I am not publishing the MDF file to the development web server: I am trying to access the MDF file on my computer from the app that is running on a web server.

我的假设是,该Web应用程序将使用连接字符串来寻找关于谁是计算机正在运行的应用程序,MDF文件,但显然它不是这种简单甚至可能没有可能呢?

My assumption would be that the web app would use the connection string to look for that MDF file on whoever's computer is running the app, but apparently it is not this simple and may not even be possible?

推荐答案

这是行不通的。你需要设置,也许,在本地PC上的SQL Server防爆preSS实例,里面创建一个类似的MDF数据库(或只是将其导出彻底)。您可以连接到这条SQL防爆preSS例如更换connectionsString到(例如)SERVERNAME,并引用数据库。一个很好的例子是在 http://www.connectionstrings.com/ 。 SQL Server的防爆preSS是免费的,而且也是相当比VS任何内部更加强劲。

It won't work. You need to setup, perhaps, a SQL Server Express instance in a local PC, and inside create a database similar to your MDF (or just export it outright). You can connect to this SQL Express instance changing the connectionsString to a (example) "SERVERNAME" and referencing the database. A great example is at http://www.connectionstrings.com/. SQL Server Express is free, and also fairly more robust than anything internal in VS.

这篇关于我可以连接到的LocalDB MDF文件的计算机上从正在Web服务器上运行一个Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆