连结c#连结mysql 应该是这样的 MySQLDriverCS.MySQLConnection conn = new MySQLDriverCS.MySQLConnection (new MySQLDriverCS.MySQLConnectionString("127.0.0.1",database,use id,password).AsString); 例如 MySQLDriverCS.MySQLConnection conn = new MySQLDriverCS.MySQLConnection (new MySQLDriverCS.MySQLConnectionString("localhost","test","root","").AsString); 这样就可以连上数据库
http://community.csdn.net/Expert/topic/3121/3121364.xml?temp=7.302493E-02
using System.Data.SqlClient;public class DataReaderSql
{
public static int Main(string[] args)
{
string source =“data source=(local);initial catalog=Northwind;integrated security=SSPI;”; string select = "SELECT ContactName,CompanyName FROM Customers" ; SqlConnection conn = new SqlConnection ( source ) ; try
{
using ( conn )
{
conn.Open ( ) ; SqlCommand cmd = new SqlCommand ( select , conn ) ; using ( SqlDataReader aReader = cmd.ExecuteReader ( ) )
{
while ( aReader.Read ( ) )
Console.WriteLine ( "'{0}' from {1}" , aReader.GetString(0) , aReader.GetString ( 1 ) ) ; aReader.Close ( ) ;
} conn.Close ( ) ;
}
}
catch ( Exception e )
{
Console.WriteLine ( e ) ;
Console.WriteLine ( ) ;
Console.WriteLine ( "Chances are your database does not have a user" ) ;
Console.WriteLine ( "called QSUser, or you do not have the NetSDK database installed." ) ;
} return 0;
}
}
其中datasource后表示为默认本地服务器
用这个"Data Source=server;Database=mydb;User ID=username;Password=pwd;Command Logging=false" 也不行
应该是这样的
MySQLDriverCS.MySQLConnection conn = new MySQLDriverCS.MySQLConnection (new MySQLDriverCS.MySQLConnectionString("127.0.0.1",database,use id,password).AsString);
例如
MySQLDriverCS.MySQLConnection conn = new MySQLDriverCS.MySQLConnection (new MySQLDriverCS.MySQLConnectionString("localhost","test","root","").AsString);
这样就可以连上数据库