private static void UsingConnection(SampleConnection connection, Action <SampleConnection> act)
        {
            // remember the connection string so that we can reset it if credentials are wiped
            string holdConnectionString = connection.ConnectionString;
            bool   openingConnection    = connection.State == ConnectionState.Closed;

            if (openingConnection)
            {
                connection.Open();
            }
            try
            {
                act(connection);
            }
            finally
            {
                if (openingConnection && connection.State == ConnectionState.Open)
                {
                    // if we opened the connection, we should close it
                    connection.Close();
                }
                if (connection.ConnectionString != holdConnectionString)
                {
                    connection.ConnectionString = holdConnectionString;
                }
            }
        }
        protected override string GetDbProviderManifestToken(DbConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentException("connection");
            }

            SampleConnection sampleConnection = connection as SampleConnection;

            if (sampleConnection == null)
            {
                throw new ArgumentException("The connection is not of type 'SampleConnection'.");
            }

            if (string.IsNullOrEmpty(sampleConnection.ConnectionString))
            {
                throw new ArgumentException("Could not determine storage version; a valid storage connection or a version hint is required.");
            }

            bool closeConnection = false;

            try
            {
                if (sampleConnection.State != ConnectionState.Open)
                {
                    sampleConnection.Open();
                    closeConnection = true;
                }

                StoreVersion version = StoreVersionUtils.GetStoreVersion(sampleConnection);
                if (version == StoreVersion.Sql9)
                {
                    return(SampleProviderManifest.TokenSql9);
                }
                else
                {
                    return(StoreVersionUtils.GetVersionHint(version));
                }
            }
            finally
            {
                if (closeConnection)
                {
                    sampleConnection.Close();
                }
            }
        }
Ejemplo n.º 3
0
 private static void UsingConnection(SampleConnection connection, Action<SampleConnection> act)
 {
     // remember the connection string so that we can reset it if credentials are wiped
     string holdConnectionString = connection.ConnectionString;
     bool openingConnection = connection.State == ConnectionState.Closed;
     if (openingConnection)
     {
         connection.Open();
     }
     try
     {
         act(connection);
     }
     finally
     {
         if (openingConnection && connection.State == ConnectionState.Open)
         {
             // if we opened the connection, we should close it
             connection.Close();
         }
         if (connection.ConnectionString != holdConnectionString)
         {
             connection.ConnectionString = holdConnectionString;
         }
     }
 }