c#连接到mysql 的连接字符串怎么写

 我来答
huanglenzhi
2016-04-18 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117538 获赞数:517196
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
ODBC DSN
ODBC -- MyODBC Driver -- local database
ODBC -- MyODBC Driver -- remote database
ODBC -- MySQL ODBC 3.51 Driver
OleDb
.NET DataProvider from CoreLab

// ODBC DSN

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
"Dsn=DsnName;" +
"Uid=UserName;" +
"Pwd=Secret;";
conn.Open();

// ODBC -- MyODBC Driver -- local database

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
"Driver={MySql};" +
"Server=localhost;" +
"Option=16834;" +
"DataBase=DataBaseName;"
conn.Open();

// ODBC -- MyODBC Driver -- remote database

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
"Driver={MySql};" +
"Server=db.domain.com;" +
"Option=131072;" +
"Port=3306;" +
"Stmt=;" +
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;"
conn.Open();

// ODBC -- MySQL ODBC 3.51 Driver

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
"Driver={MySql ODBC 3.51 Driver};" +
"Server=ServerName;" +
"Option=16834;" +
"Port=3306;" +
"Stmt=;" +
"DataBase=DataBaseName;" +
"Uid=UserName;" +
"Pwd=Secret;"
conn.Open();

// or

using System.Data.Odbc;

OdbcConnection conn = new OdbcConnection();
conn.ConnectionString =
"DRIVER={MySql ODBC 3.51 Driver};" +
"SERVER=ServerName;" +
"DATABASE=DataBaseName;" +
"USER=UrerName;" +
"PASSWORD=Secret;"
conn.Open();

// OleDb

using System.Data.OleDb;

OleDbConnection conn = new OleDbConnection();
conn.ConnectionString =
"Provider=MySqlProv;" +
"Data Source=ServerName;" +
"User id=UserName;" +
"Password=Secret;"
conn.Open();

// .NET DataProvider from CoreLab

using CoreLab.MySql;

MySqlConnection conn = new MySqlConnection();
conn.ConnectionString =
"Host=ServerName;" +
"DataBase=DataBaseName;" +
"Protocol=TCP;" +
"Port=3306;" +
"Direct=true;" +
"Compress=false;" +
"Pooling=true;" +
"Min Pool Size=0;" +
"Max Pool Size=100;" +
"Connection Lifetime=0;" +
"User id=UserName;" +
"Password=Secret;" +
conn.Open();
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式