Ağustos 23, 2023
Okuma süresi: 12 dakika
Sizler için C# ile bir çok veri tabanına bağlantı yapabilmeniz için bağlantı cümlelerini bir araya getirdim. Makale içinde bulunan veritabanları şunlardır:
Umarım faydasını görürsünüz.
1
2
3
4
5
6
7
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Dsn=DsnName;" + "Uid=UserName;" + "Pwd=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
8
9
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server};" + "Server=DataBaseNamex;" + "DataBase=DataBaseName;" + "Uid=UserName;" + "Pwd=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server};" + "Server=ServerName;" + "DataBase=DataBaseName;" + "Uid=;" + "Pwd=;" ; conn.Open(); // or var conn = new OdbcConnection(); conn.ConnectionString = "Driver={SQL Server};" + "Server=ServerName;" + "DataBase=DataBaseName;" + "Trusted_Connection=Yes;" ; conn.Open(); |
1
2
3
4
5
6
7
8
9
|
using System.Data.OleDb; var conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB;" + "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "User id=UserName;" + "Password=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.OleDb; var conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB;" + "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "Integrated Security=SSPI;" ; conn.Open(); |
1
2
3
4
5
6
7
8
9
10
|
using System.Data.OleDb; var conn = new OleDbConnection(); conn.ConnectionString = "Driver=SQLOLEDB;" + "Network Library=DBMSSOCN;" + "Data Source=xxx.xxx.xxx.xxx,1433;" + "Initial Catalog=DataBaseName;" + "User id=UserName;" + "Password=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.SqlClient; var conn = new SqlDbConnection(); conn.ConnectionString = "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "User id=UserName;" + "Password=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
|
using System.Data.SqlClient; var conn = new SqlConnection(); conn.ConnectionString = "Data Source=ServerName;" + "Initial Catalog=DataBaseName;" + "Integrated Security=SSPI;" ; conn.Open(); |
1
2
3
4
5
6
7
8
9
|
using System.Data.SqlClient; var conn = new SqlConnection(); conn.ConnectionString = "Network Library=DBMSSOCN;" + "Data Source=xxx.xxx.xxx.xxx,1433;" + "Initial Catalog=DataBaseName;" + "User Id=UserName;" + "Password=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
8
9
|
using System.Data.SqlClient; var conn = new SqlConnection(); conn.ConnectionString = "Data Source=.\SQLExpress;" + "User Instance=true;" + "User Id=UserName;" + "Password=Secret;" + "AttachDbFilename=|DataDirectory|DataBaseName.mdf;" conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.SqlClient; var conn = new SqlConnection(); conn.ConnectionString = "Data Source=.\SQLExpress;" + "User Instance=true;" + "Integrated Security=true;" + "AttachDbFilename=|DataDirectory|DataBaseName.mdf;" conn.Open(); |
1
2
3
4
5
6
7
8
9
10
11
|
using System.Data.SqlClient; AppDomain.CurrentDomain.SetData( "DataDirectory" , "C:\MyPath\"); var conn = new SqlConnection(); conn.ConnectionString = "Data Source=.\SQLExpress;" + "User Instance=true;" + "User Id=UserName;" + "Password=Secret;" + "AttachDbFilename=|DataDirectory|DataBaseName.mdf;" conn.Open(); |
1
2
3
4
5
6
7
8
9
10
|
using System.Data.SqlClient; AppDomain.CurrentDomain.SetData( "DataDirectory" , "C:\MyPath\"); var conn = new SqlConnection(); conn.ConnectionString = "Data Source=.\SQLExpress;" + "User Instance=true;" + "Integrated Security=true;" + "AttachDbFilename=|DataDirectory|DataBaseName.mdf;" conn.Open(); |
1
2
3
4
5
6
7
8
9
|
using System.Data.SqlClient; var conn = new SqlConnection(); conn.ConnectionString = "Data Source=.\SQLExpress;" + "User Instance=true;" + "User Id=UserName;" + "Password=Secret;" + "AttachDbFilename=C:\MyPath\DataBaseName.mdf;" conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.SqlClient; var conn = new SqlConnection(); conn.ConnectionString = "Data Source=.\SQLExpress;" + "User Instance=true;" + "Integrated Security=true;" + "AttachDbFilename=C:\MyPath\DataBaseName.mdf;" conn.Open(); |
1
2
3
4
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Dsn=DsnName" ; conn.Open(); |
1
2
3
4
5
6
7
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" + "Dbq=c:\myPath\myDb.mdb;" + "Uid=Admin;Pwd=;" ; conn.Open(); |
1
2
3
4
5
6
7
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" + "Dbq=c:\myPath\myDb.mdb;" + "SystemDb=c:\myPath\myDb.mdw;" ; conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};" + "Dbq=c:\myPath\myDb.mdb;" + "Exclusive=1;" ; "Uid=Admin;Pwd=;" ; conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.OleDb; var conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=c:\mypath\myDb.mdb;" + "User id=admin;" + "Password=" ; conn.Open(); |
1
2
3
4
5
6
7
|
using System.Data.OleDb; var conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=c:\mypath\myDb.mdb;" + "System Database=c:\mypath\myDb.mdw;" ; conn.Open(); |
1
2
3
4
5
6
7
|
using System.Data.OleDb; var conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=c:\mypath\myDb.mdb;" + "Database Password=Secret;" conn.Open(); |
1
2
3
4
5
6
7
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Dsn=DsnName;" + "Uid=UserName;" + "Pwd=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.Odbc; var conn = new OdbcConnection(); conn.ConnectionString = "Driver={Microsoft ODBC for Oracle};" + "Server=OracleServer.world;" + "Uid=UserName;" + "Pwd=Secret;" ; conn.Open(); |
1
2
3
4
5
6
7
8
|
using System.Data.Odbc; var conn =
|