private void button1_Click(object sender, EventArgs e)
{
//打开数据库连接
SqlConnection conn = new SqlConnection("server=localhost; uid=sa; pwd=sa123456");
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
string sql = "CREATE DATABASE MyDataBase on primary" + "(name=MyDataBase,filename='F:\\MyDataBase.mdf',size=5,filegrowth=1)";
sql += "log on" + "(name=MyDataBase_log,filename='F:\\MyDataBase_log.ldf',size=3,filegrowth=10%)";
SqlCommand cmd = new SqlCommand(sql, conn);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("数据库创建成功。");
}
catch (SqlException ae)
{
MessageBox.Show("数据库创建失败。" + ae.Message.ToString());
}
}
c#创建数据库
最新推荐文章于 2024-04-29 22:49:38 发布