shahroz butt
shahroz butt

Reputation: 168

Modify app.config to connect to a database file in computer with no SQL Server Management Studio installed

I created a software using .net4 which uses ORM and connects to database. So when I need to connect to a file I have to first open SQL Server Management Studio and attach the database to it and then I am able to use my software if I don't do this it throws an exception that the underlying provider failed to open.

Now I want to deploy the software to my brothers computer who doesn't have Visual Basic and SQL Server installed on his computer (but he has the .net framework) so is there a way I can modify my app.config to point to the database file instead and I don't need to attach the file to the SQL Server?

Simply I don't want to attach or detach the file to the database again and again how can the .net automatically attach it.

Upvotes: 2

Views: 1641

Answers (2)

RoelF
RoelF

Reputation: 7573

Indeed, install the SQL Server 2012 Express LocalDB (it is likely already installed with your Visual Studio 2012 installation) and then modify the connection string as follows:

connectionstring="data source=(LocalDB)\v11.0;attachdbfilename=c:\MyDatabaseFile.mdf;integrated security=True;"

the (LocalDB)\v11.0 part is where you point at the LocalDB "instance", and you can attach any mdf file you want. Keep in mind that this locks up the mdf file, so you cannot have it open in Management Studio and run your app.

Upvotes: 1

agent-j
agent-j

Reputation: 27913

You mentioned attaching a database, but not wanting to install SQL Server. I would take a look at the SQL Server Express LocalDB. While it is technically installed, it is not installed as a Windows Service, so it is much lighter than full SQL server or SQL Express.

Upvotes: 0

Related Questions