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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#连接到mysql 的连接字符串怎么写相关的知识,希望对你有一定的参考价值。

参考技术A C#版mysql连接字符串

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();

以上是关于c#连接到mysql 的连接字符串怎么写的主要内容,如果未能解决你的问题,请参考以下文章

从 vs2010 连接到 mysql 的问题

C# Dapper SQL Server 连接错误:连接字符串中不存在 Dapper 连接到另一个数据库

使用 ODBC 和用户输入连接字符串在 C# 应用程序中连接到 Oracle 11g

如何在不实际安装连接器的情况下通过 C# 使用 mysql 连接器连接到 mysql

如何使用 C# 连接到 Blob 存储容器

mysql可以Windows身份验证登录吗?如果有C#的连接字符串怎么写啊??