/// <summary>
        /// Initializes a new instance of the <see cref="BusinessServiceDatabase"/> class.
        /// </summary>
        /// <param name="databaseInstanceName">The name or network address of the instance of SQL Server to connect to.</param>
        /// <param name="databaseName">The name of the database associated with the connection.</param>
        /// <param name="appPoolIdentityName">Name of the identity of the app pool.</param>
        /// <param name="servicesName">Business services instance name.</param>
        /// <param name="createBehavior">Database creation behavior.</param>
        /// <param name="sampleDataScript">Script to execute that contains sample data to prepopulate database with.</param>
        internal BusinessServiceDatabase(string databaseInstanceName, string databaseName, string appPoolIdentityName, string servicesName, CreateDatabaseBehavior createBehavior, string sampleDataScript)
        {
            if (string.IsNullOrEmpty(databaseInstanceName))
                throw new ArgumentNullException("databaseInstanceName");
            if (string.IsNullOrEmpty(databaseName) && createBehavior == CreateDatabaseBehavior.ReuseExistingOnly)
                throw new ArgumentNullException("databaseName");
            if (string.IsNullOrEmpty(appPoolIdentityName))
                throw new ArgumentNullException("appPoolIdentityName");

            _databaseInstanceName = databaseInstanceName;
            _databaseName = !string.IsNullOrEmpty(databaseName) ? databaseName : "IH_Services_" + servicesName + "_" + DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
            _databaseConnectionString = (new SqlConnectionStringBuilder() { DataSource = _databaseInstanceName, InitialCatalog = _databaseName, IntegratedSecurity = true, Enlist = true, ConnectTimeout = 15, MultipleActiveResultSets = true }).ConnectionString;
            _serverConnectionString = (new SqlConnectionStringBuilder() { DataSource = _databaseInstanceName, IntegratedSecurity = true, Enlist = true, ConnectTimeout = 15, MultipleActiveResultSets = true }).ConnectionString;
            _appPoolIdentityName = appPoolIdentityName;
            _createBehavior = createBehavior;
            _sampleDataScript = sampleDataScript;

            EnsurePublicDBUserInfo();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BusinessServiceDatabase"/> class.
        /// </summary>
        /// <param name="serviceInstancePath">The root physical path of an existing service instance.</param>
        /// <param name="databaseBehavior">Database create behavior.</param>
        /// <param name="sampleDataScript">Script to execute that contains sample data to prepopulate database with.</param>
        internal BusinessServiceDatabase(string serviceInstancePath, CreateDatabaseBehavior databaseBehavior, string sampleDataScript)
        {
            if (string.IsNullOrEmpty(serviceInstancePath))
                throw new ArgumentNullException("serviceInstancePath");

            // Get existing service instance configuration
            var config = BusinessServiceConfiguration.GetConfigForInstance(serviceInstancePath);

            var connectionStringBuilder = new SqlConnectionStringBuilder(config.ConnectionStrings.ConnectionStrings[Constants.ServiceHostConnectionStringName].ConnectionString);

            _databaseInstanceName = connectionStringBuilder.DataSource;
            _databaseName = connectionStringBuilder.InitialCatalog;
            _databaseConnectionString = connectionStringBuilder.ConnectionString;
            _serverConnectionString = (new SqlConnectionStringBuilder() { DataSource = _databaseInstanceName, IntegratedSecurity = true, Enlist = true, ConnectTimeout = 15, MultipleActiveResultSets = true }).ConnectionString;
            _appPoolIdentityName = IISUtilities.GetAppPoolForApp(serviceInstancePath).ProcessModel.UserName;
            _createBehavior = databaseBehavior;
            _sampleDataScript = sampleDataScript;

            EnsurePublicDBUserInfo();
        }