开发者

Having trouble connecting C# executable to database file on remote computer

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->Da开发者_StackOverflowta 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜