public static Boolean DBConnect()
        {
            if (isConnected)
            {
                return(true);
            }
            SQLSettings sqlSettings = SQLSettings.GetActiveSQLSettings();

            if (!string.IsNullOrEmpty(sqlSettings.Server.Trim()) && !string.IsNullOrEmpty(sqlSettings.Database.Trim()) &&
                !string.IsNullOrEmpty(sqlSettings.Username.Trim()) && !string.IsNullOrEmpty(sqlSettings.Password.Trim()))
            {
                connectionStringMain = String.Format("Data Source={0};Network Library=DBMSSOCN;Initial Catalog={1};Persist Security Info=True; MultipleActiveResultSets=True;User ID={2};Password={3};Max Pool Size=4000",
                                                     sqlSettings.Server.Replace(":", ",").Replace(" ", ""), sqlSettings.Database, sqlSettings.Username, sqlSettings.Password);
            }
            else
            {
                Err = "Database connection parameters are not set!";
                return(false);
            }

            try
            {
                if (connectionMain == null)
                {
                    connectionMain = new SqlConnection();
                }
                if (connectionMain.State == System.Data.ConnectionState.Open)
                {
                    connectionMain.Close();
                    connectionMain.Dispose();
                    SqlConnection.ClearPool(connectionMain);
                }
                SqlCommand com = new SqlCommand();
                connectionMain.ConnectionString = connectionStringMain;
                com.Connection = connectionMain;
                connectionMain.Open();
                isConnected = true;
                return(true);
            }
            catch (Exception ex)
            {
                Err = ex.Message;
                return(false);
            }
        }
Beispiel #2
0
 public MainForm()
 {
     InitializeComponent();
     sqlSettings = SQLSettings.GetActiveSQLSettings();
     Logins      = SQLSettings.getLoginInformation();
 }