如何在运行Visual Studio 2010中创建的项目的安装程序时自动附加/还原sql数据库文件 [英] How to attach/restore sql database file automatically while running setup of a project made in Visual Studio 2010

查看:123
本文介绍了如何在运行Visual Studio 2010中创建的项目的安装程序时自动附加/还原sql数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网络中,我有一个带有5个客户端的SERVER.在我的一个客户端中,我有Visual Studio 2010,在我的SERVER中有OS 2003和SQL SERVER2005.我在SERVER中创建了一个数据库.在安装VB 2010的特定客户端中,我通过从SERVER中创建的数据库添加数据源来创建一个项目.现在,我使用设置和部署向导来构建我的项目.我的简单应用程序可以在网络中的任何客户端计算机上正常运行.它将数据完美地保存在我在SERVER中创建的数据库中.但是,当我尝试在另一个服务器的另一个网络中运行我的应用程序时,我无法.仅当我在企业管理器中手动将数据库从我自己的SERVER还原到该SERVER时,它才能在其他SERVER中运行.

现在,当我在该服务器上安装应用程序时,如何在其他服务器上创建/附加/还原数据库.我在VB和SQL中要做的事情.请使用VB代码.还请告诉我,在我的应用程序执行开始时,如何将setup.exe安装在用于服务器名称,USER和密码的其他SERVER Promt中,以便数据库可以自动附加到SQL SERVER.


这很容易:)在SQL Management Studio中,右键单击您的数据库,选择生成脚本",按照向导进行操作,您应该具有从头开始创建数据库所需的脚本

2.您需要向客户要求
-SQL Server详细信息
-SQL管理员登录凭据或集成登录
-要删除/创建的数据库名称(永远不要假设客户对您选择的数据库名称感到满意)
-创建它的路径,或使用SQL默认值

3.您需要在#2的服务器上执行在#1中生成的脚本

4.您的应用程序需要了解#2的一些内容
-服务器
-dbname

项目2和3可以通过多种方式完成,在这里,我们在MSI/setup.exe文件中使用自定义脚本,自定义表和自定义UI,这可能超出了您希望的范围,但是这里有一个示例将参数传递到配置文件的设置和部署项目 [ ^ ]讨论如何做到这一点

您可以将由#1生成的sql脚本安装到目录中,然后使用来自UI的信息让VBscript自定义操作运行它们.
或者,您也可以在首次运行应用程序时运行VB exe,这应该很容易识别,因为您的应用程序将没有#4所需的任何信息

那应该让你走;)

要考虑的另一件事是在数据库中有一个schemaNumber表,然后您可以通过在v1#1脚本和v2#1脚本上运行windiff来创建更新脚本<​​/blockquote>

In my network I have a SERVER with 5 clients. In one of my client, I have Visual Studio 2010 and in my SERVER I have OS 2003 and SQL SERVER 2005. I have created a database in my SERVER . In the particular client where my VB 2010 is installed I have made a project by adding datasource from the database created in the SERVER. Now I have build my project with setup and deployment wizard. My simple application runs fine from any of my client machine in my network. It saves data perfectly in my database created in the SERVER. BUT when I tried to run my application in a different network in another SERVER, I cant. It runs in different SERVER only if I restore my database from my own SERVER to that SERVER manualy in Enterprise manager.

Now how can I create/attach/restore my database in a different SERVER while installing my application in that SERVER. What I have to do in VB and SQL.Kindly use VB code. Kindly also tell me how the setup.exe while installing in a different SERVER promt for the SERVER name, USER, Password at the begining of execution of my application so that the database may be attached to the SQL SERVER automatically.

解决方案

Ok - let''s break this down ...

1. You need the SQL ''definition'' of your DB, logins, indices et al

This one is easy :) In SQL Management Studio, right click your DB, choose Generate Scripts, follow the wizard, and you should have the script required to create your DB from scratch

2. You need to ask the customer for
- SQL server details
- SQL admin login credentials, or integrated login
- name of the db to drop/create (don''t ever assume the customer is happy with your choice of DB name)
- path to create it to, or use the SQL default

3. You need to execute the scripts generated in #1 on the server in #2

4. Your application needs to understand some items from #2
- server
- dbname

Items 2 & 3 can be done in a number of ways, here, we use Custom Scripts, Custom Tables and Custom UIs inside the MSI/setup.exe file, this may be beyond the scope you wish to take on, but there''s an example A Setup and Deployment project that passes parameters to the configuration file[^] that talks about doing bits of that

You could install the sql scripts generated from #1 into a directory, then have a VBscript custom action run them, using information from the UI

Or alternatively, you could have a VB exe run the first time your app is run - and that should be easy to identify, because your app won''t have any information it needs from #4

That should get you going ;)

Another thing to consider is having a schemaNumber table in your DB, then you can create update scripts by simply running a windiff over v1 #1 script and v2 #1 scripts


这篇关于如何在运行Visual Studio 2010中创建的项目的安装程序时自动附加/还原sql数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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