protected override string DbCreateDatabaseScript(string providerManifestToken, StoreItemCollection storeItemCollection) { if (providerManifestToken == null) { throw new ArgumentNullException("providerManifestToken must not be null"); } if (storeItemCollection == null) { throw new ArgumentNullException("storeItemCollection must not be null"); } return(DdlBuilder.CreateObjectsScript(storeItemCollection)); }
protected override void DbCreateDatabase(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("The connection is not of type 'SampleConnection'."); } string databaseName = GetDatabaseName(sampleConnection); if (string.IsNullOrEmpty(databaseName)) { throw new InvalidOperationException("Initial Catalog is missing from the connection string"); } string dataFileName, logFileName; GetDatabaseFileNames(sampleConnection, out dataFileName, out logFileName); string createDatabaseScript = DdlBuilder.CreateDatabaseScript(databaseName, dataFileName, logFileName); string createObjectsScript = DdlBuilder.CreateObjectsScript(storeItemCollection); UsingMasterConnection(sampleConnection, conn => { // create database CreateCommand(conn, createDatabaseScript, commandTimeout).ExecuteNonQuery(); }); // Clear connection pool for the database connection since after the 'create database' call, a previously // invalid connection may now be valid. sampleConnection.ClearPool(); UsingConnection(sampleConnection, conn => { // create database objects CreateCommand(conn, createObjectsScript, commandTimeout).ExecuteNonQuery(); }); }