0

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."

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" />

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.

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Gerry
  • 628
  • 6
  • 16
  • 4
    This is NOT possible. You cannot access a file on the client machine from a web application. There are way too many reasons why you cannot do that. How would you know the client machine path, What about security, It 's just not web apps. – Praveen Paulose Mar 30 '15 at 20:12
  • 3
    No, the `.mdf` file is really a **SQL Server** database, and if you really want to have multiple users from web apps using this database, you need to setup a **SQL Server database server** on a machine in your network somewhere, and let everyone connect to that shared server – marc_s Mar 30 '15 at 20:28
  • :-) If you are just doing it for testing purposes, try sharing the folder from which your MDF file is located in your local machine then you can change your connection string pointing to the shared folder. :-) technically it should work but not advisable for prod use. – youji.xii Mar 31 '15 at 03:26

1 Answers1

1

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.

Lord Relix
  • 922
  • 5
  • 23
  • 50
  • 1
    Or just attach the `.mdf` you already have to a SQL Server instance and then use it *on the server* - easy as that ! – marc_s Mar 30 '15 at 20:26