I created a console application to deploy our package to have it be automated. It's based on your Database Installer Sample. Most of the code is reading in the command line arguments, but this is where I decide to run either by a connection string or explicit settings:
_databaseMigrator = ConnectionString.Length > 0 ?
new DatabaseMigrator(connectionString, this) :
new DatabaseMigrator(SQLServer, winAuth, this, SQLUserName, SQLPassword);
_databaseMigrator.DeployMetaData(PackagePath, FrameworkPassword);
When I run the app with these settings, it works flawlessly:
// This works:
SQLServer = "MyServer";
winAuth = true;
SQLUserName = "";
SQLPassword = "";
When I run it with a connection string (that we use on our main application using StrataFrame), it does not work and fails on dropping the exisiting database. We drop the database in the Pre-Deploy Script.
// This does not work:
connectionString = "Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True";
The error I get back is this:
*** Starting Deployment...
Package Path = P:\PathToPackage\DDT_Packages\MyPackage.pkg
Connection String = Data Source=MyDataSource;Initial Catalog=MyDatabase;Integrated Security=True
Windows Authen. = True
Checking SQL Connection...
SQL Connection is valid
Executing Pre-Deployment Scripts, Executing Pre-Deployment Scripts
*** Error Executing Script, SqlException
Cannot drop database "MyDatabase" because it is currently in use.
Source : .Net SqlClient Data Provider
Stack Trace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName,Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at MicroFour.StrataFrame.DBEngine.SQL.DatabaseMigrator.ExecuteProfileScripts(DataView scriptsToExecute)
***
*** Error Deploying Meta-Data, ThreadAbortException
Thread was being aborted.
Source : MicroFour StrataFrame DBEngine
Stack Trace:
at MicroFour.StrataFrame.DBEngine.SQL.DatabaseMigrator.ExecuteProfileScripts(DataView scriptsToExecute)
at MicroFour.StrataFrame.DBEngine.SQL.DatabaseMigrator.ExecutePreProfileScripts()
at MicroFour.StrataFrame.DBEngine.SQL.DatabaseMigrator.EnsureDatabases()
at MicroFour.StrataFrame.DBEngine.SQL.DatabaseMigrator.DeployMetaDataThread()
***
It almost seems like the DatabaseMigrator instance is grabbing hold of the database preventing it from being dropped, but
only when used with a connection string. What am I missing here? I can zip up the project and send it to you directly if you need the code.
Thanks,
Derek