是的,你確實可以做到這一點...... 創建一個新的類,並使其成爲SQLConnection類型的對象或者它是。
它的目的應該是創建和維護與數據庫的連接並執行各種任務(這部分是可選的,因爲您可以直接傳遞查詢)。
從網上
class DBConnect
{
private MySqlConnection connection;
private string server;
private string database;
private string uid;
private string password;
//Constructor
public DBConnect()
{
Initialize();
}
//Initialize values
private void Initialize(String[] connectionInfo)
{
server = connectionInfo[0];
database = connectionInfo[1];
uid = connectionInfo[2];
password = connectionInfo[3];
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
}
//open connection to database
private bool OpenConnection()
{
}
//Close connection
private bool CloseConnection()
{
}
//Insert statement
public void Insert()
{
}
//Update statement
public void Update()
{
}
//Delete statement
public void Delete()
{
}
//Select statement
public List <string> [] Select()
{
}
//Count statement
public int Count()
{
}
//Backup
public void Backup()
{
}
//Restore
public void Restore()
{
}
}
得到這個所以,當你有不同的數據庫,你可以去,如:
DBConnect srv001 = new DBConnect({server1,db1,uid1,pw1});
DBConnect srv002 = new DBConnect({server2,db2,uid2,pw2});
所以,現在你有2個不同的數據庫
2個併發連接