internal static SqlConnectionHolder GetConnection(string connectionString, bool revertImpersonation) {
            string strTempConnection = connectionString.ToUpperInvariant();
            if (strTempConnection.Contains(s_strUpperDataDirWithToken)) {
                EnsureDBFile(connectionString);
            }

            // Only block UserInstance for LocalDB connections
            if (strTempConnection.Contains(s_localDbName)) {
                EnsureNoUserInstance(connectionString);
            }

            SqlConnectionHolder holder = new SqlConnectionHolder(connectionString);
            bool closeConn = true;
            try {
                try {
                    holder.Open(null, revertImpersonation);
                    closeConn = false;
                }
                finally {
                    if (closeConn) {
                        holder.Close();
                        holder = null;
                    }
                }
            }
            catch {
                throw;
            }
            return holder;
        }
Esempio n. 2
0
        internal static SqlConnectionHolder GetConnection(string connectionString, bool revertImpersonation)
        {
            string strTempConnection = connectionString.ToUpperInvariant();

            if (strTempConnection.Contains(s_strUpperDataDirWithToken))
            {
                EnsureDBFile(connectionString);
            }

            // Only block UserInstance for LocalDB connections
            if (strTempConnection.Contains(s_localDbName))
            {
                EnsureNoUserInstance(connectionString);
            }

            SqlConnectionHolder holder = new SqlConnectionHolder(connectionString);
            bool closeConn             = true;

            try {
                try {
                    holder.Open(null, revertImpersonation);
                    closeConn = false;
                }
                finally {
                    if (closeConn)
                    {
                        holder.Close();
                        holder = null;
                    }
                }
            }
            catch {
                throw;
            }
            return(holder);
        }
 internal static SqlConnectionHolder GetConnection(string connectionString, bool revertImpersonation)
 {
     if (connectionString.ToUpperInvariant().Contains("|DATADIRECTORY|"))
     {
         EnsureSqlExpressDBFile(connectionString);
     }
     SqlConnectionHolder holder = new SqlConnectionHolder(connectionString);
     bool flag = true;
     try
     {
         try
         {
             holder.Open(null, revertImpersonation);
             flag = false;
         }
         finally
         {
             if (flag)
             {
                 holder.Close();
                 holder = null;
             }
         }
     }
     catch
     {
         throw;
     }
     return holder;
 }