1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

Fix minor bug when testing if database already exists (#1452)

* Fix minor bug when testing if database already exists

* Add newline at end of file

* Remove unused import
This commit is contained in:
Vince Grassia 2021-07-09 18:51:28 -04:00 committed by GitHub
parent def1a86348
commit 1941ba0a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

1
.gitignore vendored
View File

@ -215,3 +215,4 @@ bitwarden_license/src/Sso/wwwroot/lib
bitwarden_license/src/Sso/wwwroot/css bitwarden_license/src/Sso/wwwroot/css
.github/test/build.secrets .github/test/build.secrets
**/CoverageOutput/ **/CoverageOutput/
.idea/*

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Data;
using System.Data.SqlClient; using System.Data.SqlClient;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
@ -39,18 +40,17 @@ namespace Bit.Migrator
{ {
databaseName = "vault"; databaseName = "vault";
} }
var commandBuilder = new SqlCommandBuilder();
var databaseNameQuoted = new SqlCommandBuilder().QuoteIdentifier(databaseName); var databaseNameQuoted = new SqlCommandBuilder().QuoteIdentifier(databaseName);
var command = new SqlCommand( var command = new SqlCommand(
"IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = '@DatabaseName') = 0) " + "IF ((SELECT COUNT(1) FROM sys.databases WHERE [name] = @DatabaseName) = 0) " +
"CREATE DATABASE " + databaseNameQuoted + ";", connection); "CREATE DATABASE " + databaseNameQuoted + ";", connection);
command.Parameters.Add("@DatabaseName", System.Data.SqlDbType.VarChar); command.Parameters.Add("@DatabaseName", SqlDbType.VarChar).Value = databaseName;
command.Parameters["@DatabaseName"].Value = databaseName;
command.Connection.Open(); command.Connection.Open();
command.ExecuteNonQuery(); command.ExecuteNonQuery();
command.CommandText = "IF ((SELECT DATABASEPROPERTYEX([name], 'IsAutoClose') " + command.CommandText = "IF ((SELECT DATABASEPROPERTYEX([name], 'IsAutoClose') " +
"FROM sys.databases WHERE [name] = '@DatabaseName') = 1) " + "FROM sys.databases WHERE [name] = @DatabaseName) = 1) " +
"ALTER DATABASE " + databaseNameQuoted + " SET AUTO_CLOSE OFF;"; "ALTER DATABASE " + databaseNameQuoted + " SET AUTO_CLOSE OFF;";
command.ExecuteNonQuery(); command.ExecuteNonQuery();
} }