這裏是我的代碼:C#和SQL服務器與錯誤 「CREATE DATABASE」 語句
String str;
SqlConnection myConn = new SqlConnection("Server=localhost;Integratedsecurity=SSPI;database=master");
str = "CREATE DATABASE JoesData ON PRIMARY " +
"(NAME = JoesData, " +
"FILENAME = 'C:\\JoesData.mdf', " +
"SIZE = 3MB, MAXSIZE = 10MB, FILEGROWTH = 10%) " +
"LOG ON (NAME = MyDatabase_Log, " +
"FILENAME = 'C:\\MyJLog.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();
}
}
以下是錯誤:
任何想法可能會導致什麼呢?預先感謝您的幫助。
請將錯誤文本粘貼到您的問題中。 – SLaks
錯誤表示SQL Server實例未找到或無法訪問。這應該是相當自我解釋爲問題的起源=>您的SQL Server實例未找到或無法訪問。 –
您可以在此處寫錯誤代碼而不是flickr照片:-) –