如何使用asp.net将数据库文件附加到sql server management studio [英] how to attach a database file to sql server management studio by using asp.net

查看:120
本文介绍了如何使用asp.net将数据库文件附加到sql server management studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库文件,在我的项目中必须要求通过代码将此数据库附加到sql server auto.请帮助我,非常感谢.

i have a database file, in my project must requiment attach this database to sql server auto by code.Help me please and thanks so much.

推荐答案


如果我的理解是正确的,则需要使用C#将数据库备份文件附加到sql服务器.能否请您检查下面的代码.这可能对您有帮助.我无法编译代码.

Hi
If my understanding is correct, you need to attach a database backup file to the sql server using C#. Can you please check the below code. This may help you. I couldn''t compile the code.

using System.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

  string ConnectionString = "Your connections string";
            SqlConnection conSql = new SqlConnection(ConnectionString);
            ServerConnection con = new ServerConnection(conSql);
            Server server = new Server(con);
            System.Collections.Specialized.StringCollection sCollection = new    System.Collections.Specialized.StringCollection();
            sCollection.Add("filePath");
            server.AttachDatabase("newdatabasename", sCollection);



To get the namespace, please refer the following dlls.
1. C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfo.dll

2. C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.ConnectionInfoExtended.dll

3. C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.Utility.dll

4. C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Management.UtilityEnum.dll

5.C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Smo.dll

6.C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.SmoExtended.dll


NB:
This all dlls may not need. Actually i didn't check all. And also there may be better mechanisms to do this job.


这篇关于如何使用asp.net将数据库文件附加到sql server management studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆