Exemple #1
0
        //-------------------------------------------------------------------------

        private bool Initialise(DbConnectionSettings settings)
        {
            try
            {
                Connection = new SqlConnection(settings.ConnectionString);
                Connection.Open();
            }
            catch (Exception ex)
            {
                // Something's gone wrong, close any connections that were opened.
                try
                {
                    if (Connection != null)
                    {
                        Connection.Close();
                    }
                }
                catch {}

                throw new Exception(
                          "Database connection error." +
                          Environment.NewLine +
                          Environment.NewLine +
                          ex.Message);
            }

            return(true);
        }
Exemple #2
0
        //-------------------------------------------------------------------------

        public DbConnection(string serverName,
                            string dbName,
                            string username,
                            string password)
        {
            DbConnectionSettings settings = new DbConnectionSettings();

            settings.ServerName  = serverName;
            settings.DbName      = dbName;
            settings.SqlUserName = username;
            settings.SqlPassword = password;

            settings.UseSqlAuthentication = (settings.SqlUserName.Length > 0);

            Initialise(settings);
        }