Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix errors setting up dev site #3642

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions Build/Cake/database.cake
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Database tasks for your local DNN development site
using System.Data.SqlClient;

Task("ResetDatabase")
.Does(() =>
.Does(() =>
{
var script = ReplaceScriptVariables(LoadScript("db-connections-drop"));
ExecuteScript(script);
Expand All @@ -15,6 +16,13 @@ Task("ResetDatabase")

public const string ScriptsPath = @".\Build\Cake\sql\";

private static readonly string[] GoStatement = {
"\r\nGO\r\n",
"\nGO\n",
"\nGO\r\n",
"\r\nGO\n",
};

public string LoadScript(string scriptName) {
var script = scriptName + ".local.sql";
if (!System.IO.File.Exists(ScriptsPath + script)) {
Expand All @@ -30,16 +38,16 @@ public string ReplaceScriptVariables(string script) {
.Replace("{DBLogin}", Settings.DnnSqlUsername);
}

public bool ExecuteScript(string ScriptStatement)
public bool ExecuteScript(string scriptStatement)
{
try
{
using (var connection = new System.Data.SqlClient.SqlConnection(Settings.SaConnectionString))
using (var connection = new SqlConnection(Settings.SaConnectionString))
{
connection.Open();
foreach (var cmd in ScriptStatement.Split(new string[] {"\r\nGO\r\n"}, StringSplitOptions.RemoveEmptyEntries)) {
var command = new System.Data.SqlClient.SqlCommand(cmd, connection);
command.ExecuteNonQuery();
foreach (var cmd in scriptStatement.Split(GoStatement, StringSplitOptions.RemoveEmptyEntries)) {
var command = new SqlCommand(cmd, connection);
command.ExecuteNonQuery();
}
connection.Close();
}
Expand All @@ -49,4 +57,4 @@ public bool ExecuteScript(string ScriptStatement)
return false;
}
return true;
}
}
4 changes: 2 additions & 2 deletions Build/Cake/sql/create-db.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
IF db_id('{DBName}') IS NOT NULL DROP DATABASE {DBName};
IF db_id('{DBName}') IS NOT NULL DROP DATABASE [{DBName}];
GO

CREATE DATABASE [{DBName}] ON PRIMARY
( NAME = N'{DBName}', FILENAME = N'{DBPath}\{DBName}.mdf')
LOG ON
LOG ON
( NAME = N'{DBName}_log', FILENAME = N'{DBPath}\{DBName}_log.ldf')
GO

Expand Down