using System;using System.Collections.Generic;using System.Text;using System.Data;using System.Data.OleDb;using System.Runtime.Serialization;using System.Runtime.Serialization.Formatters.Binary;using System.Diagnostics;namespace Common.File...{ public class DBConnect ...{ public DBConnect() ...{ } private DBConnectInfo dbc; private string encryName; private string encryPwd; CryptoService cs = new CryptoService(); private void InitRoles() ...{ OleDbConnection con = new OleDbConnection(); string role = cs.Descrypt(encryName); string pwd = cs.Descrypt(encryPwd); con.ConnectionString = "Provider=" + dbc.Provider + ";Initial Catalog=" + dbc.Database + ";Password=" + pwd + ";User ID=" + role + ";Data Source=" + dbc.DataSource; OleDbDataAdapter oda = new OleDbDataAdapter("Select role_id,role_pwd From sys_roles", con); try ...{ con.Open(); DataSet ds = new DataSet(); oda.Fill(ds, "roles"); foreach (DataRow dr in ds.Tables["roles"].Rows) ...{ } con.Close(); con.Dispose(); oda.Dispose(); } catch (System.Exception e) ...{ Debug.Assert(true, e.Message); } } public OleDbConnection OleDbConnection(string loginrole,string as_Database,string as_DataSource) ...{ OleDbConnection dbcon = null; string role = cs.Descrypt(this.encryName); string pwd = cs.Descrypt(this.encryPwd); OleDbConnection con = new OleDbConnection(); string cstr = "Provider=" + dbc.Provider + ";Initial Catalog=" + dbc.Database + ";Password=" + pwd + ";User ID=" + role + ";Data Source=" + dbc.DataSource; con.ConnectionString = cstr; string sql = "Select role_pwd From sys_roles Where role_id='" + loginrole + "'"; OleDbCommand cmd = new OleDbCommand(sql, con); OleDbDataReader reader; try ...{ con.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) ...{ pwd = reader.GetString(0); pwd = Decrypt(pwd); break; } cstr = "Provider=" + dbc.Provider + ";Initial Catalog=" + dbc.Database + ";Password=" + pwd + ";User ID=" + loginrole + ";Data Source=" + dbc.DataSource; dbcon = new OleDbConnection(cstr); } catch ...{ return null; } return dbcon; } private string Decrypt(string pwd) ...{ return cs.Descrypt(pwd); } }} 2--- using System;using System.Collections.Generic;using System.Text;namespace Common.File...{ public class DBConnectInfo ...{ Fields#region Fields private string _provider; private string _database; private string _datasource; private string _role; #endregion Properties#region Properties public string Provider ...{ get ...{ return _provider; } set ...{ _provider = value; } } public string Database ...{ get ...{ return _database; } set ...{ _database = value; } } public string DataSource ...{ get ...{ return _datasource; } set ...{ _datasource = value; } } public string Role ...{ get ...{ return _role; } set ...{ _role = value; } } #endregion Methods#region Methods #endregion }}