// .NET Data Provider -- Default Relative Path
//
Standard Connection
|
using System.Data.SqlClient;
SqlConnection conn
= new SqlConnection();
conn.ConnectionString
=
"Data
Source=.\SQLExpress;" +
"User
Instance=true;" +
"User
Id=UserName;" +
"Password=Secret;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
|
// .NET Data Provider -- Default Relative Path
//
Trusted Connection
|
using System.Data.SqlClient;
SqlConnection conn
= new SqlConnection();
conn.ConnectionString
=
"Data
Source=.\SQLExpress;" +
"User
Instance=true;" +
"Integrated
Security=true;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
|
// .NET Data Provider -- Custom Relative Path
//
Standard Connection
|
using System.Data.SqlClient;
AppDomain.CurrentDomain.SetData(
"DataDirectory",
"C:\MyPath\");
SqlConnection conn
= new SqlConnection();
conn.ConnectionString
=
"Data
Source=.\SQLExpress;" +
"User
Instance=true;" +
"User
Id=UserName;" +
"Password=Secret;" +
"AttachDbFilename=|DataDirectory|DataBaseName.mdf;"
conn.Open();
|
No comments :
Post a Comment