Connect VB.net to SQL Server Express mdf

1.5k views Asked by At

I am very experienced with MS Access, but I am trying to transition to to VB.net and SQL Server. I am trying to build a multi-user database. The mdf file would be on some computer on the LAN, and each connected computer would have the application. I need a way to let the end users select the path to the mdf file, so only one mdf file is used. I've got a working method, but I want to make sure I'm on the right track. When a form loads, I have this:

My.Settings("mslConnectionString") = "Server=(localdb)\v11.0;Integrated Security=true;AttachDbFileName=E:\Documents\Visual Studio 2013\Projects\WindowsApplication3\WindowsApplication3\msl.mdf;"

Is that an appropriate way to link to the backend mdf file? What I envision doing is making a form where the end user can navigate to the correct network path, and then I guess I'd store that path in a text document. When the form is opened, it would first look at the text document and change the path at runtime. Thanks in advance.

1

There are 1 answers

3
Bradley Uffner On BEST ANSWER

What you have there is a "LocalDB" connection string. LocalDB is a lightweight implementation of SQL server that can attach directly to an mdf file. It is commonly used to have one "client" attached to it at a time. You can't share that same .mdf file directly from multiple applications like you can with Access.

If you want to do something like that with SQL, you need to install SQL Server. SQL Server will attach to the .mdf file and allow multiple connected clients to use it at the same time.

The full version of SQL Server is /very/ expensive, but there is a "Lite" version that is free, with a few restrictions, called SqlExpress.

It is also possible to set up LocalDB in such a way as it hosts the database file as if it were a full sql server, but this involves a little bit more work and complexity. If you want more information about this, check out MSDN, specifically the section that talks about "Named Instances".