简体   繁体   English

使用SQL在VB.NET中“另存为”或“重命名”数据库的最佳方法

[英]Best way to “Save As” or “Rename” a database in VB.NET using SQL

In my application I wanted to Open an existing blank database (called "New File" - with full structure but no data), then fill the database using the application then save the database with a different name and path. 在我的应用程序中,我想打开一个现有的空白数据库(称为“新文件”-具有完整结构,但没有数据),然后使用该应用程序填充数据库,然后使用不同的名称和路径保存该数据库。 What is the most appropriate method of doing this? 最合适的方法是什么? I use SQLEXPRESS and VB.NET 2010. 我使用SQLEXPRESS和VB.NET 2010。

The best supported solution would be to use SQL Server Management Objects , which provides full programmatic control to SQL Server, and is largely (exclusively?) what Management Studio uses. 最佳支持的解决方案是使用SQL Server Management Objects ,它为SQL Server提供完全的编程控制,并且在很大程度上(专有地)是Management Studio所使用的。 Something to be aware of is the difference between the logical name and physical name of the database. 需要注意的是数据库的逻辑名称和物理名称之间的区别。 You original question does not address which you are attempting to rename, but they are completely separate. 您原来的问题没有解决您要重命名的问题,但是它们是完全分开的。 For the former, there should be no active processes open in the database. 对于前者,数据库中不应打开任何活动进程。 For the latter, you will probably find it easiest to Detach, move the file using OS conventions, then re-Attach. 对于后者,您可能会发现最简单的方法是分离,使用OS约定移动文件,然后重新附加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM