接続を開けないなどのエラーがたくさんあります.VS 2010 c# wpfを使用しています
String str;
SqlConnection myConn = new SqlConnection("Server=localhost;Integrated security=SSPI;database=master");
str = " CREATE DATABASE "
+ " ON PRIMARY "
+ " (NAME = " + "MyDatabase_Data" + ", "
+ " FILENAME = '" + "C:\\MyDatabaseData.mdf" + "', "
+ " SIZE = 2MB,"
+ " FILEGROWTH =" + "10%" + ") "
+ " LOG ON (NAME =" + "MyDatabase_Log" + ", "
+ " FILENAME = '" + "C:\\MyDatabaseLog.ldf" + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH =" + "10%" + ") ";
SqlCommand myCommand = new SqlCommand(str, myConn);
try
{
myConn.Open();
myCommand.ExecuteNonQuery();
MessageBox.Show("DataBase is Created Successfully", "MyProgram", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "MyProgram", MessageBoxButton.OK, MessageBoxImage.Information);
}
finally
{
if (myConn.State == ConnectionState.Open)
{
myConn.Close();
}
}