Beispiel #1
0
        protected void CreateConnection()
        {
            try
            {
                if (settings.UseIntegratedAuthentication)
                {
                    connection = new SqlServerConnection(settings.ServerName);
                }
                else
                {
                    connection = new SqlServerConnection(settings.ServerName, settings.UserName, settings.Password);
                }

                connection.Connect();

                if (!connection.IsUserValid())
                {
                    string msg = string.Format(
                        "The user is not valid for SQL Server {0}",
                        settings.ServerName);
                    throw new SqlExporterConnectionException(msg);
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format(
                    "There was an error while trying to connect to the SQL Server {0}",
                    settings.ServerName);
                throw new SqlExporterConnectionException(msg, ex);
            }
        }