Ejemplo n.º 1
0
        private void SaveLoginSettings()
        {
            Logins.username = (textBoxUsername.Text);
            Logins.password = (textBoxPassword.Text);

            SQLSettings.setLoginInformation(Logins);
        }
Ejemplo n.º 2
0
        private void SaveSqlSettings()
        {
            sqlSettings.Server   = txt_Server.Text;
            sqlSettings.Database = txt_Database.Text;
            sqlSettings.Username = txt_Username.Text;
            sqlSettings.Password = txt_Password.Text;

            SQLSettings.setActiveSQLSettings(sqlSettings);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
        public static void setActiveSQLSettings(SQLSettings aSettings)
        {
            if (!Directory.Exists(AppPaths.AppSettingsPath))
            {
                Directory.CreateDirectory(AppPaths.AppSettingsPath);
            }

            var filename = Path.Combine(AppPaths.AppSettingsPath, "AppData.dat");

            using (var fs = File.Open(filename, FileMode.Create))
            {
                try
                {
                    var xmlser = new XmlSerializer(typeof(SQLSettings));
                    xmlser.Serialize(fs, aSettings);
                }
                catch
                {
                }
                //fs.Close();
                //fs.Dispose();
            }
        }
Ejemplo n.º 5
0
 public MainForm()
 {
     InitializeComponent();
     sqlSettings = SQLSettings.GetActiveSQLSettings();
     Logins      = SQLSettings.getLoginInformation();
 }