SQL Server Express的sp_attachDB过程 [英] sp_attachDB procedure for SQL Server Express

查看:95
本文介绍了SQL Server Express的sp_attachDB过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是SQL Server Express的新手.目前,我正在使用SSMS手动附加数据库,但是我需要通过代码来实现.
我在互联网上进行了很多搜索,但无法真正启动任何内容.

我知道有一个sp_attach过程,但不知道如何使用它,然后如何通过我的应用程序的设置调用它.如何使用SQLDMO

请给我任何帮助吗?

谢谢

Hi,
I am newbie to SQL Server Express. At the moment I am manually attaching the DBs using SSMS but I need to do it through code.
I have searched a lot over internet but could not really start anything.

I know there is a sp_attach procedure but donot know how to use it and then how to call that through my application''s setup. How to use SQLDMO

Could any help be given to me please?

Thanks

推荐答案

请勿使用sp_attach_db().如MSDN所述,将来可能会删除它.
使用CREATE DATABASE ....进行连接

Do not use sp_attach_db(). As MSDN states it may be removed in the future.
Use CREATE DATABASE .... FOR ATTACH

CREATE DATABASE [C:\xyz.MDF] ON
( FILENAME = N'C:\xyz.mdf' ),
( FILENAME = N'C:\xyz_log.LDF' )
 FOR ATTACH



如果您使用的是SSMS,请在单击确定"按钮之前,检查顶部的脚本"按钮.点击它它会向您显示该操作的基础脚本.您可以从中学习.



If you''re using SSMS, before hitting the ''OK'' button, check for the Script button on top. Click it & it''ll show you the underlying script for the action. You can learn from it.


根据您的需要,通过创建数据库来附加数据库的另一种方法是在连接期间使用AttachDbFilename参数附加数据库文件.

例如,如果SQL Server安装在本地且仅用于一个用户,则通常使用此方法.请参阅: http://www.connectionstrings.com/sql-server-2008 [
Depending on your needs, another option to attaching the database by creating it is to attach the database file during the connection using AttachDbFilename parameter.

This is commonly used for example if the SQL Server installation is local and for one user. See: http://www.connectionstrings.com/sql-server-2008[^]


这篇关于SQL Server Express的sp_attachDB过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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