views:

51

answers:

1

Hello Friends,

Using VC# I've created a staff management app that, upon its first run, is expected to query the user for the path to a (.mdf) database which will reside on a remote computer. A resulting path may be something like

string dbPath = @"P:\remoteComputer\public\StaffTool\ExamplePersonnelDatabase.mdf";

Then I'm placing this string into a connection string template as so:

string dbConnectTemplate = @"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Integrated Security=True;Connect Timeout=30;User Instance=True";
string dbConnectionString = String.Format(dbConnectionTemplate,dbPath);

Then I'm attempting to connect to the database LINQ to SQL style

ManagementDBDataContext db = new ManagementDBDataContext(
                dbConnectionString);

At this point, an error pop's up stating that

The file "P:\remoteComputer\public\StaffTool\ExamplePersonnelDatabase.mdf" is on a network path that is not supported for database files.

An attempt to attach an auto-named database for file P:\remoteComputer\public\StaffTool\ExamplePersonnelDatabase.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

As I am relatively new to databases, I completely do not understand this message. And obviously, the file is not on a UNC share.

Any ideas?


Jim Lamb recommended that I connect to an instance of SQL server running remotely. Considering that I'm using LINQ to SQL, what refactoring do I have to do to make this happen? Other ideas still welcome - especially "push this button and everything will work" solutions.


Another clue: A coworker said that there used to be some way to work through Control Panel->Administrative Tools->Data Sources(ODBC) so that a remote database could be viewed from my computer as if it was local. The coworker didn't know any more details besides this.

+3  A: 

You are attempting to connect to a database file on another machine over a network connection, which isn't supported by SQL Express. You'll need to make a local copy and attach to that, or connect to an instance of SQL that's running on the same machine as the MDF file.

Jim Lamb
The second option there seem more attractive, but how much refactoring do I have to do to do with my code in order to connect to a remote instance of SQL? Consider that I'm using LINQ to SQL.
John Berryman
You shouldn't need to modify your code at all - just your connection string. Then, of course, you'll need to install SQL Express on the remote machine, attach the MDF file, etc.
Jim Lamb