Share

Connection String for access SQL server using C#


#Connection String to access SQL server *.mdf & *.ldf file.

1. For SQL server database file attachment for installation folder needs *.mdf and *.ldf file using below connection string.

<add name="MovieDBContext" 

connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=Movies;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated ecurity=True" providerName="System.Data.SqlClient" />

 

2.Attach a database file on connect to a local SQL Server Express instance

<add name="MovieDBContext"

connectionString="Data Source=.\SQLEXPRESS;Initial catalog=Movies;AttachDbFilename=C:\MyFolder\MyDataFile.mdf;ntegrated Security=True" providerName="System.Data.SqlClient" />

 

1