欢迎来到忆约科技! 手机版

C# 社区推荐

当前位置:首页 > 编程专栏 > C# > 正文

C# 常用数据库连接字符串, SQL Server, MySQL, Oracle, Access mdb

编辑时间:2020年08月07日 05:08 作者:E小编

C# 常用数据库连接字符串, SQL Server, MySQL, Oracle, Access mdb
// SqlServer-Windows Authentication
string connectionString = "Data Source=127.0.0.1,1433;Initial Catalog=TestDB;connect timeout=10;Integrated Security=True";
// SqlServer-Account & Password
string connectionString = "Data Source=127.0.0.1,1433;Initial Catalog=TestDB;uid=sa;pwd=123456";

// MySql-Account & Password
string connectionString = "server=127.0.0.1;port=3306;database=TestDB;charset=utf8;user id=root;password=123456;pooling=false;";

// Oracle-Account & Password
string connectionString = "Data Source=(DESCRIPTION=(ADDRESS =(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1522))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=TestDB)));User Id=scott;Password=123456";

// Access-connect mdb
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\Test.mdb" + ";Jet OLEDB:Database Password=123456;Persist Security Info=False";
// Access-connect accdb
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\Test.accdb" + ";Jet OLEDB:Database Password=123456;Persist Security Info=False";
// Access-connect mdb - ASP.NET(App_Data)
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"|DataDirectory|\\TestDB.mdb\";Jet OLEDB:database password=987654321;Persist Security Info=False";
// Access-connect accdb - ASP.NET(App_Data)
string connectionString = "Provider=Microsoft.Jet.OLEDB.12.0;Data Source=\"|DataDirectory|\\TestDB.accdb\";Jet OLEDB:database password=987654321;Persist Security Info=False";
// Access-connect mdb - ASP.NET
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~//Test.mdb") + ";Jet OLEDB:Database Password=123456;Persist Security Info=False";
// Access-connect accdb - ASP.NET
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.Web.HttpContext.Current.Server.MapPath("~//Test.accdb") + ";Jet OLEDB:Database Password=123456;Persist Security Info=False";


二维码