我连接到数据库(sql server 2000)之前,总要在sql server 2000的企业管理器中先手动的通过"数据库"--"所有任务"--"附加数据库"来把自己数据库的MDF文件添加进来.
程序中使用的是简单的数据库连接字符串(数据源是本地,登陆类型为本地windows验证,数据库名为MYDB).
sql server 2000安装时选的是windows验证.我想在程序中完成"数据库"--"所有任务"--"附加数据库"来把自己数据库的MDF文件添加进来.这个动作,请问如何写代码实现啊?
程序中使用的是简单的数据库连接字符串(数据源是本地,登陆类型为本地windows验证,数据库名为MYDB).
sql server 2000安装时选的是windows验证.我想在程序中完成"数据库"--"所有任务"--"附加数据库"来把自己数据库的MDF文件添加进来.这个动作,请问如何写代码实现啊?
解决方案 »
- 弱弱问句,你们编程都有做UML?在你们编程中UML非常重要?有没有案例推荐的?
- Gridview与Excel的结合,请教。
- C# string 与Ascii码转换问题
- 如何用C#实现添加Web自定义桌面链接
- VS2005中自带的sql server express 2005怎么用?
- 一个ASP.NET的移动web应用,在pda手机上访问是出现了base64的转换错误,请问怎么解决
- C#在哪些领域有应用,详细求解
- 照抄书本有错误,哪位大哥大姐帮帮忙啊
- VS2005无法启动,急急!!!!
- 急救:谁能给我一个文本框中只能输入数字的判断函数啊?
- 如何让Windows服务显示一个Form与用户交互,在线等
- 散分啦,菜鸟问题为何table.GetChanges();返回null
string @strsp_attach_db; //sp_attach_db.ini内容:
//Data Source = (local);
//Integrated Security = SSPI;
//Initial Catalog = Master; try
{
fileConnection = new FileStream("..\\..\\sp_attach_db.ini", FileMode.Open);
}
catch (FileNotFoundException notfile)
{
MessageBox.Show(notfile.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
StreamReader sr = new StreamReader(fileConnection);
strsp_attach_db = sr.ReadToEnd();
if (strsp_attach_db == null)
{
fileConnection.Close();
sr.Close();
return;
}
else
{
fileConnection.Close();
sr.Close();
} SqlConnection sp = new SqlConnection(@strsp_attach_db);
string strdbname = @"exec sp_attach_db @dbname = 'BookManager',";
string strfilename1 = @"'..\..\BookManager_Data.MDF',";
string strfilename2 = @"'..\..\BookManager_Log.LDF'";
string ok = strdbname + strfilename1 + strfilename2;
SqlCommand sqlspcom = new SqlCommand(ok, sp);
sp.Open();
sqlspcom.ExecuteNonQuery();
sp.Close();