protected override bool DbDatabaseExists(DbConnection connection, int?commandTimeout, StoreItemCollection storeItemCollection) { if (connection == null) { throw new ArgumentNullException("connection must not be null"); } if (storeItemCollection == null) { throw new ArgumentNullException("storeItemCollection must not be null"); } SampleConnection sampleConnection = connection as SampleConnection; if (sampleConnection == null) { throw new ArgumentException("connection must be a valid SampleConnection"); } string databaseName = GetDatabaseName(sampleConnection); bool exists = false; UsingMasterConnection(sampleConnection, conn => { StoreVersion storeVersion = StoreVersionUtils.GetStoreVersion(conn); string databaseExistsScript = DdlBuilder.CreateDatabaseExistsScript(databaseName); int result = (int)CreateCommand(conn, databaseExistsScript, commandTimeout).ExecuteScalar(); exists = (result == 1); }); return(exists); }
/// <summary> /// Constructor /// </summary> /// <param name="manifestToken">A token used to infer the capabilities of the store</param> public SampleProviderManifest(string manifestToken) : base(SampleProviderManifest.GetProviderManifest()) { // GetStoreVersion will throw ArgumentException if manifestToken is null, empty, or not recognized. _version = StoreVersionUtils.GetStoreVersion(manifestToken); _token = manifestToken; }
private static void ValidateVersion(string manifestToken) { if (string.IsNullOrWhiteSpace(manifestToken)) { throw new ArgumentException("Could not determine storage version. manifestToken is null or whitespace string."); } // GetSqlVersion will throw ArgumentException if manifestToken is null, empty, or not recognized. StoreVersion storeVersion = StoreVersionUtils.GetStoreVersion(manifestToken); // SQL spatial support is only available for SQL Server 2008 and later if (storeVersion < StoreVersion.Sql10) { throw new InvalidOperationException("Spatial types and functions are only supported by SQL Server 2008 or later."); } }
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(); } } }