Answers for "Create a SQL Server Database programmatically"

SQL
0

Create a SQL Server Database programmatically

String str;
 SqlConnection myConn = new SqlConnection ("Server=localhost;Integrated security=SSPI;database=master");

str = "CREATE DATABASE MyDatabase ON PRIMARY " +
 "(NAME = MyDatabase_Data, " +
 "FILENAME = 'C:\\MyDatabaseData.mdf', " +
 "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%)" +
 "LOG ON (NAME = MyDatabase_Log, " +
 "FILENAME = 'C:\\MyDatabaseLog.ldf', " +
 "SIZE = 1MB, " +
 "MAXSIZE = 5MB, " +
 "FILEGROWTH = 10%)";

SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
    myConn.Open();
    myCommand.ExecuteNonQuery();
    MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
    MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
    if (myConn.State == ConnectionState.Open)
    {
        myConn.Close();
    }
}
Posted by: Guest on December-03-2020
0

create a sql server database programmatically

String str;
 SqlConnection myConn = new SqlConnection ("Server=localhost;Integrated security=SSPI;database=master");

str = "CREATE DATABASE MyDatabase ON PRIMARY " +
 "(NAME = MyDatabase_Data, " +
 "FILENAME = 'C:\\MyDatabaseData.mdf', " +
 "SIZE = 2MB, MAXSIZE = 10MB, FILEGROWTH = 10%)" +
 "LOG ON (NAME = MyDatabase_Log, " +
 "FILENAME = 'C:\\MyDatabaseLog.ldf', " +
 "SIZE = 1MB, " +
 "MAXSIZE = 5MB, " +
 "FILEGROWTH = 10%)";

SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
Posted by: Guest on August-13-2021

Code answers related to "Create a SQL Server Database programmatically"

Code answers related to "SQL"

Browse Popular Code Answers by Language