Home Database Mysql Tutorial VS2010(英文版)打包部署自动安装数据库

VS2010(英文版)打包部署自动安装数据库

Jun 07, 2016 pm 03:29 PM
vs2010 Install Pack database automatic English version deploy

上周第一次打包自己的系统时,在别人电脑上使用不了,因为远程连接不了我的数据库,所以要想在别人的电脑上运行我的系统则需要手动附加我的数据库。 下面我来为大家介绍一种方法:在打包程序时将数据库一起打包,这样安装程序的时候会自动附加数据库(前提是

上周第一次打包自己的系统时,在别人电脑上使用不了,因为远程连接不了我的数据库,所以要想在别人的电脑上运行我的系统则需要手动附加我的数据库。

下面我来为大家介绍一种方法:在打包程序时将数据库一起打包,这样安装程序的时候会自动附加数据库(前提是该电脑上有SQL SERVER)。

一).创建部署项目
1. 打开VS.NET2011。
2.在“File”菜单上指向“New Project”。
3. 在“New Project”对话框中,选择“Installed Templates”窗格中的”Other Project Types”中的“Setup and Deployment”,然后选择“Visual Studio Installer”窗格中的“Setup Project”。在“Name”框中键入 MySetup。
 
4. 单击“OK”关闭对话框。
5. 项目被添加到解决方案资源管理器中,并且文件系统编辑器打开。

6. 在“Property”窗口中,选择 ProductName 属性,并键入 数据库打包安装。

二).将 主程序 项目的输出添加到部署项目中

1. 在“File System”中,选择“Application Folder”。右击指向“Add”,然后选择“File”。

2. 在“Add File”对话框中,选择你程序的dll及exe文件. 

3. 单击“打开”关闭对话框.

三).创建安装程序类
1. 在“Solution Explorer”中的“Solution’MySetup’”上右键选择“Add”后选择“New Project”。
2. 在“New Project”对话框中,选择“Other Languages”窗格中的“Visual Basic“,然后选择“Class Library”。在“Name”框中键入 InstallDB。
 
3. 单击“OK”关闭对话框。
4. 从“InstallDB”类库下右键选择"Add”中的“New Item”。

5. 在“New Item”对话框中选择“General”后选择“Installer Class”。在“Name”框中键入 InstallDB。 
6. 单击“Add”关闭对话框。
7. “InstallDB”安装程序类详细代码附后。 
 

四).创建自定义安装对话框
1.   在解决方案资源管理器中选择“MySetup”项目。右键然后在“View”菜单上选择“User Interface”。

2.   在用户界面编辑器中,选择“Install”下的“Start”节点选择“Add Dialog”。
3    在“Add Dialog”对话框中,选择“Textboxs (A)”对话框,然后单击“OK”关闭对话框。
4.   在“Textboxs (A)”右键菜单上,选择“Move up”。重复此步骤,直到“Textboxs (A)”对话框位于“Installation Folder”节点之上。
5    在“Textboxs (A)”的“Property”窗口中,选择 BannerText 属性并键入:安装数据库。
6.   选择 BodyText 属性并键入:安装程序将在目标机器上安装数据库。
7.   选择 Edit1Label 属性并键入:数据库名称:
8 .  选择 Edit1Property 属性并键入 DBNAME
9.   选择 Edit1Value 属性并键入: budgetSysDB
10. 选择 Edit2Label 属性并键入:服务器名:
11. 选择 Edit2Property 属性并键入 SERVER
12. 选择 Edit2Value 属性并键入:(local)
13. 选择 Edit3Label 属性并键入:用户名:
13. 选择 Edit3Value 属性并键入:sa
15. 选择 Edit3Property 属性并键入 USER
16. 选择 Edit4Label 属性并键入:密码:
18. 选择 Edit4Property 属性并键入 PWD
19. 选择Edit2Visible 属性,设置为 false;选择Edit2Visible、Edit3Visible 和 Edit4Visible 属性,并将它们设置为 true 

五).创建自定义操作
1. 在解决方案资源管理器中选择“MySetup”项目,右键在“View”菜单上选择“Custom Actions”。
2. 在自定义操作编辑器中选择“Install”节点。右键选择“Add Custom Action……”。
3. 在“Select Item in Project”对话框中,双击“Application Folder”。
4. 单击”Add output”按钮选择”Project”中的” InstallDB”,在下面框中选择”Primary Output”(此项一般为默认),然后单击“OK”关闭对话框。
 

5. 在”Primary Output from InstallDB(Active)的属性窗口中,选择 CustomActionData属性并键入:/dbname=[DBNAME] /server=[SERVER] /user=[USER] /pwd=[PWD] /targetdir="[TARGETDIR]/"。
附:/targetdir="[TARGETDIR]/"是安装后的目标路径,为了在installDB类中获得安装后的路径,我们设置此参数。  

六).添加数据库文件:
1. 在解决方案资源管理器中选择“MySetup”项目,右键在“Add”选择“file”。
2.把数据文件”BookManage_Data.MDF”” BookManage_Log.LDF”添加到”MySetup”。 

七).”InstallDB”安装程序类代码(vb.net)

 

Imports System.ComponentModel
Imports System.Configuration.Install
Imports System.Collections.Generic
Imports System
Imports System.Data
Imports System.Data.SqlClient

Namespace InstallDB

Partial Public Class InstallerDB
    Inherits Installer

    '''


    ''' 必须的设计器变量
    '''

    ''' 2011-4-27 10:20 by dan
    Private components As System.ComponentModel.IContainer = Nothing


    '''


    ''' 构造函数
    '''

    ''' 2011-4-27 10:20 by dan
    Public Sub New()

        MyBase.New()
        'This call is required by the Component Designer.
        InitializeComponent()
        'Dim state As System.Collections.IDictionary = New Hashtable
        'Add initialization code after the call to InitializeComponent

    End Sub

    '''


    ''' 清理所有正在使用的资源
    '''

    ''' 2011-4-27 10:20 by dan
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not IsNothing(components) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

#Region "组件设计器生成的代码"
    '''


    ''' 设计器支持所需的方法——不要使用代码编辑器修改此方法的内容
    '''

    '''
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container
    End Sub
#End Region


#Region "数据库文件为mdf和ldf文件"
    '''


    ''' 附加数据库的mdf文件和ldf文件
    '''

    ''' sql语句
    ''' 数据名
    ''' mdf文件名
    ''' ldf文件名
    ''' 2011-4-27 15:57 by dan
    Private Sub CreateDataBase(ByVal strSql As String, ByVal DataName As String, ByVal strMdf As String, ByVal strLdf As String, ByVal path As String)
        '附加数据库
        Dim str As String
        Dim myConn As SqlConnection = New SqlConnection(strSql)
        str = "EXEC sp_attach_db @dbname='" & DataName & "',@filename1='" & strMdf & "',@filename2='" & strLdf & "'"

        Dim myCommand As SqlCommand = New SqlCommand(str, myConn)

        myConn.Open()
        myCommand.ExecuteNonQuery()
        myConn.Close()
    End Sub

    '''


    ''' 重写安装代码
    '''

    '''
    ''' 2011-5-7 18:46 by dan
    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)

        MyBase.Install(stateSaver)

        Dim server As String = Me.Context.Parameters("server")
        Dim uid As String = Me.Context.Parameters("user")
        Dim pwd As String = Me.Context.Parameters("pwd")
        Dim path As String = Me.Context.Parameters("targetdir")
        '连接sql
        Dim strSql As String = "server=" & server & ";uid=" & uid & ";pwd=" & pwd & ";database=master"

        Dim DataName As String = "BookManage"
        Dim strMdf As String = path & "/BookManage_Data.mdf"
        Dim strLdf As String = path & "/BookManage_Log.ldf"

        Me.CreateDataBase(strSql, DataName, strMdf, strLdf, path)
    End Sub
#End Region
End Class

End Namespace 

八).打包時加入卸载功能:

   1.在打包項目中添加文件msiexec.exe(一般可在c:/windows/system32/下找到)

2.在File System中选择Application Folder,在msiexec.exe上按右鍵,选择”Create Shortcut to msiexec.exe”,重命名快捷方式为"卸载".  

3.更改此快捷方式的Arguments 为"/x {產品id}",产品id的值为打包項目的ProductCode属性值. 

 

C#版:http://www.cnblogs.com/neozhu/archive/2007/02/24/654985.html

 

 

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How does Go language implement the addition, deletion, modification and query operations of the database? How does Go language implement the addition, deletion, modification and query operations of the database? Mar 27, 2024 pm 09:39 PM

Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Yolov10: Detailed explanation, deployment and application all in one place! Yolov10: Detailed explanation, deployment and application all in one place! Jun 07, 2024 pm 12:05 PM

1. Introduction Over the past few years, YOLOs have become the dominant paradigm in the field of real-time object detection due to its effective balance between computational cost and detection performance. Researchers have explored YOLO's architectural design, optimization goals, data expansion strategies, etc., and have made significant progress. At the same time, relying on non-maximum suppression (NMS) for post-processing hinders end-to-end deployment of YOLO and adversely affects inference latency. In YOLOs, the design of various components lacks comprehensive and thorough inspection, resulting in significant computational redundancy and limiting the capabilities of the model. It offers suboptimal efficiency, and relatively large potential for performance improvement. In this work, the goal is to further improve the performance efficiency boundary of YOLO from both post-processing and model architecture. to this end

How does Hibernate implement polymorphic mapping? How does Hibernate implement polymorphic mapping? Apr 17, 2024 pm 12:09 PM

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

An in-depth analysis of how HTML reads the database An in-depth analysis of how HTML reads the database Apr 09, 2024 pm 12:36 PM

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to download 360 Secure Browser on your computer How to download 360 Secure Browser on your computer Apr 12, 2024 pm 01:52 PM

How to download 360 Secure Browser on your computer? It is a very secure web browser software. This browser is very rich in functions and very simple to operate. Using 360 Secure Browser to browse the web can protect user privacy and security very well. Many people like to use this browser. Browser office, but many people still don’t know how to download and install 360 Secure Browser on their computers. This article will give you a detailed introduction to the installation process of the 360 ​​Safe Browser PC version, hoping to help you solve the problem. Overview of the installation process under the computer version of 360 Secure Browser 1. On the computer’s main page, find “360 Software Manager” and enter (as shown in the picture). 2. Open 360 Software Manager and find the search box (as shown in the picture). 3. Click Search

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

See all articles