public frm_DbSettings() { _dbConnectionSettings = new Controllers.CLS_dbSettings(); // TODO: remove the instant (astract class) InitializeComponent(); string[] dbConnectionInfo = _dbConnectionSettings.getDBserverInfo(); txtServerName.Text = dbConnectionInfo[0]; txtDBName.Text = dbConnectionInfo[1]; if (dbConnectionInfo[2] == "SQL") { radioBtnSQL.Checked = true; txtDBUsername.ReadOnly = false; txtDBpassword.ReadOnly = false; txtDBUsername.Text = dbConnectionInfo[3]; } else { radioBtnWin.Checked = true; txtDBpassword.Clear(); txtDBUsername.Clear(); txtDBUsername.ReadOnly = true; txtDBpassword.ReadOnly = true; } }
public DataAcessLayer() { //Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\kfs_hospital.mdf;Integrated Security=True;Connect Timeout=30 // kh.. //Server=.\nameOfServer; Database=kfs_hospital; Integrated Security=True; // prepared conenction string from the r.click on the database on the server instance //sqlCon = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\bolli\documents\visual studio 2015\Projects\Emad Store\Emad Store\kfs_hospital.mdf';Integrated Security=True;Connect Timeout=30"); /* edited prepared one */ string[] dbServerInfo = _dbConnectionSettings.getDBserverInfo(); string dbServerName = dbServerInfo[0]; //"(LocalDB)\\MSSQLLocalDB"; string dbName = dbServerInfo[1]; //"C:\\Users\bolli\\documents\\visual studio 2015\\Projects\\Emad Store\\Emad Store\\kfs_hospital.mdf"; string authMode = dbServerInfo[2]; //"Windows"; string dbUsername = dbServerInfo[3]; //"temporary username"; string dbPasswd = dbServerInfo[4]; //"temp password"; // todo: use "AttachDbFilename" only if the user chose to store the db on the local machine // otherwise give the user an option to install the sqlserver sqlCon = new SqlConnection(@"Data Source=" + dbServerName + ";AttachDbFilename='" + dbName + "';" + (authMode == "Windows" ? "Integrated Security=True;" : "Integrated Security=false; User ID=" + dbUsername + "; Password="******";") + "Connect Timeout=3"); }
private void btnTestConeection_Click(object sender, EventArgs e) { string[] dbServerInfo = _dbConnectionSettings.getDBserverInfo(); string dbServerName = dbServerInfo[0]; //"(LocalDB)\\MSSQLLocalDB"; string dbName = dbServerInfo[1]; //"C:\\Users\emad\\documents\\visual studio 2015\\Projects\\Emad Store\\Emad Store\\kfs_hospital.mdf"; if (dbServerName == "" || dbName == "") // make sure that there is some info stored in the settings { MessageBox.Show("لا يوجد معلومات اتصال بقاعدة البيانات مخزنة في البرنامج"); return; } else { Models.DataAcessLayer dal = new Models.DataAcessLayer(); if (dal.testDBConnection()) { MessageBox.Show("الاتصال يعمل بشكل صحيح"); } else { MessageBox.Show("يوجد خطأ في الاتصال بقاعدة البيانات"); } } }