Let you look at MSDN, you don't look, and now ask:

Source: Internet
Author: User
Tags error handling file system create database install node
The following walkthrough demonstrates how to use a custom action during installation and CustomActionDataproperty to create a database and database table.
To Create an installer class
    1. On the File menu, point to New, and then select Project.
    2. In the New Project dialog box, select Visual Basic project in the Project Types pane, and then select Class Library in the Templates pane. In the Name box, type dbcustomaction.
    3. From the Project menu, choose Add New Item.
    4. In the Add New Item dialog box, select Setup class. In the Name box, type dbcustomaction.

To create a data connection object
    1. In Server Explorer, select Data Connections. Right-click and select Add Connection.
    2. In the Data Link Properties dialog box, enter a valid server name, user name, and password value for your SQL Server configuration. In the Database box, type master. Select the Allow saving password check box.
    3. Drag the new connection to the DBCustomAction.vb designer to create the SqlConnection1 object.

Create a text file that contains SQL statements to create a database
    1. In Solution Explorer, select the DBCustomAction project. From the Project menu, choose Add New Item.
    2. In the Add New Item dialog box, select Text file. In the Name box, type sql.txt(must be lowercase).
    3. Add the following content to the Sql.txt file:
      CREATE TABLE [dbo]. [Employees]  ([Name] [char] COLLATE sql_latin1_general_cp1_ci_as NOT NULL, [RSVP] [int] NULL, [Requests] [nvarchar] (4000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) on [PRIMARY]; ALTER TABLE [dbo]. [Employees] With NOCHECK ADD CONSTRAINT [pk_employees] PRIMARY KEY CLUSTERED ([Name]) on [PRIMARY];
    4. In Solution Explorer, select Sql.txt. In the Properties window, set the Build Action property to embedded resources.

Add code to the Installer class to read a text file
  1. In Solution Explorer, select DBCustomAction.vb. On the View menu, select Code.
  2. Add the following Imports statement to the top of the module:
    Imports System.ioimports System.Reflection
  3. Add the following code to the class:
    Private Function GetSQL (ByVal Name as String) as string   try       ' get The current Assembly.      dim Asm as [assembly] = [assembly]. getexecutingassembly ()        ' resources are named using a fully qualified name.       dim strm as Stream = Asm.getmanifestresourcestream (Asm.getname (). Name + "." + name)        ' Read the contents of the embedded FILE.    &N Bsp; dim reader as StreamReader = New StreamReader (strm)       return reader. ReadToEnd ()    catch ex as Exception      msgbox ("in GetSQL:" & Ex. Message)       throw ex   end tryend functionprivate Sub ExecuteSql ( ByVal DatabaseName As String, ByVal SQL as String)    dim Command as New sqlclient.sqlcommand (SQL, sqlconnEction1)    command.connection.open ()    command.connection.changedatabase ( DatabaseName)    try      command.executenonquery ()     Finally       ' Finally, blocks are a great way to ensure the CONNECTION &NB sp;      ' is always closed.      command.connection.close ( )    end tryend subprotected Sub adddbtable (ByVal strdbname as String)    Try        ' Create ' Database.      executesql ("Master", "Create DATABASE "+ strdbname"        ' Create the tables.       ExecuteSQL (strDbName, GetSQL ("Sql.txt"))    catch ex as exception         ' Errors and Abort.       msgbox ("in exception Handler: "& Ex." Message)        throw ex   end tryend SubPublic Overrides Sub Install (ByVal statesaver as System.Collections.IDictionary)    mybase.install (statesaver)     adddbtable (Me.Context.Parameters.Item ("dbname")) End Sub
  4. On the Build menu, select Generate DBCustomAction.

To Create a deployment project
    1. On the File menu, select Add Project-> new project.
    2. In the Add Project dialog box, select Install and deploy projects in the Project Types pane, and then select Setup Project in the Templates pane. In the Name box, type dbcustomaction Installer.
    3. In the Properties window, select the ProductName property and type the DB Installer.
    4. In the File System Editor, select Application Folder. On the Action menu, select Add-> project output.
    5. In the Add Project Output Group dialog box, select the primary output for the DBCustomAction project.

To Create a Custom installation dialog box
    1. Select the DBCustomAction Installer project in Solution Explorer. On the View menu, point to Editor, and then select User interface.
    2. In the User Interface Editor, select the startup node under install. On the Action menu, select Add dialog box.
    3. In the Add dialog box, select the text Box (A) dialog box.
    4. On the Action menu, select Move Up. Repeat this step until the text box (A) dialog box is above the installation folders node.
    5. In the Properties window, select the bannertext property and type specify Database Name.
    6. Select the BodyText property and type This dialog allows your to specify the name of the "database to" created on the database SE RVer.
    7. Select the Edit1Label property and type Name of DB:.
    8. Select the edit1property property and type CUSTOMTEXTA1.
    9. Select the edit2visible,edit3visible , and edit4visible properties and set them to False.

Create a custom action
    1. Select the DBCustomAction Installer project in Solution Explorer. On the View menu, point to Editor, and then select Custom Actions.
    2. Select the Install node in the Custom Action Editor. On the Action menu, select Add Custom action.
    3. In the Select Item in Project dialog box, double-click Application Folder.
    4. Select the primary output from DBCustomAction (Active) item.
    5. In the Properties window, select the customactiondata property and type /dbname=[customtexta1].
    6. On the Build menu, choose Generate Dbcustomactioninstaller.

Installing on the development computer
    • Select the DBCustomAction Installer project in Solution Explorer. On the Project menu, choose Install.
      This will run the Setup program on the development computer.

deploy to another computer
    1. In Windows Explorer, navigate to the project directory and look for the generated installer. The default path will be \documents and Settings\yourloginname\dbcustomaction installer\project configuration\ DBCustomAction Installer.msi. The default "project configuration" is "Debug."
    2. Copy the DBCustomAction Installer.msi file and all other files and subdirectories in the directory to another computer.
      Note to install on a computer that is not connected to the network, copy the file to a traditional media such as a CD-ROM.

      Double-click the Setup.exe file on the target computer to run Setup.

Uninstalling Applications
    1. In Windows Control Panel, double-click Add/Remove Programs.
    2. In the Add/Remove Programs dialog box, select DBCustomAction Setup and click Remove.
      tip To uninstall from the development computer, on the Project menu, select Uninstall.

Please see


Custom action Management in Deployment | CustomActionData Properties | Connecting to a data source via Ado.net | Error handling in Custom actions




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.