如果不存在配置檔案或不存在完整的配置檔案,則將預設配置寫入檔案中
如果存在配置檔案,則將從檔案中讀取配置檔案,獲取連線字串
/// /// serverpath.ini檔案路徑
///
private string serverpathinipath;
/// /// 獲取連線字串
///
public string getconnectionstring()
string server = publicutility.readvaluefrominifile("section", "server", "", serverpathinipath);
string database = publicutility.readvaluefrominifile("section", "database", "", serverpathinipath);
string user = publicutility.readvaluefrominifile("section", "user", "", serverpathinipath);
string password = publicutility.readvaluefrominifile("section", "password", "", serverpathinipath);
string connectionstring = "server=" + server + ";database=" + database + ";uid=" + user + ";pwd=" + password;
return connectionstring;
}
公共工具類
public static class publicutility
/// /// 寫入ini配置檔案
///
/// 段
/// 鍵名
/// 鍵值
/// 檔案路徑
public static void writevaluefrominifile(string section, string key, string value, string filepath)
}
C 連線 SQLServer 及操作
隨筆 連線 將tb user表資料新增到datagridview中 string sqlconn data source localhost initial catalog db qq persist security info true user id sa password 99990000 s...
SqlServer常用指令碼 檢視當前連線的使用者
使用sql語句檢視當前連線的使用者 select spid,db name dbid as dbname,login time last batch status hostname program name loginame from sys.sysprocesses where spid 50an...
求解 C 連線Sql server 2005
add key constr value server pc 201103212003 sqlexpress initial catalog drugshopms integrated security sspi connect timeout 30 連線也沒有提示有什麼問題,可是輸入登入框的使用者...