欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Using a Custom Action to Create a Database D

系統(tǒng) 1963 0

From http://msdn.microsoft.com/library


The following walkthrough demonstrates the use of a custom action and the CustomActionData property to create a database and database table during installation.

Note ???This walkthrough requires SQL Server on the computer where you will deploy the application.

To create an installer class

  1. On the File menu, point to New , and then choose Project .
  2. In the New Project dialog box, select Visual Basic Projects in the Project Type pane, and then choose Class Library in the Templates pane. In the Name box, type DBCustomAction .
  3. Click OK to close the dialog box.
  4. On the Project menu, choose Add New Item .
  5. In the Add New Item dialog box, choose Installer Class . In the Name box, type DBCustomAction .
  6. Click OK to close the dialog box.

To create a data connection object

  1. In Server Explorer, select Data Connections . Right-click and choose Add Connection .
  2. In the Data Link Properties dialog box, do the following:
    1. Enter the server name.
    2. Select Use Windows NT Integrated Security .
    3. In the database box, type master .
    4. Click OK to close the dialog box.
  3. Drag the new connection and drop it on the DBCustomAction.vb designer to create a sqlConnection1 object .

To create a text file that contains a SQL statement to create a database

  1. In Solution Explorer, select the DBCustomAction project. On the Project menu, choose Add New Item .
  2. In the Add New Item dialog box, choose Text File . In the Name box, type sql.txt (must be in lower case).
  3. Click OK to close the dialog box.
  4. Add the following to the sql.txt file:
              CREATE TABLE [dbo].[Employees] ([Name] [char] (30) 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];
            
  5. In Solution Explorer, select sql.txt . In the Properties window, set the BuildAction property to Embedded Resource .

To add code to the installer class to read the text file

  1. In Solution Explorer, select DBCustomAction.vb . On the View menu, choose Code .
  2. Add the following Imports statement at 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      ' Gets 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)      ' Reads the contents of the embedded file.      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 that the connection       ' is always closed.      Command.Connection.Close()   End TryEnd SubProtected Sub AddDBTable(ByVal strDBName As String)   Try      ' Creates the database.      ExecuteSql("master", "CREATE DATABASE " + strDBName)      ' Creates the tables.      ExecuteSql(strDBName, GetSql("sql.txt"))   Catch ex As Exception       ' Reports any 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, choose Build DBCustomAction .

To create a deployment project

  1. On the File menu, choose Add Project , New Project .
  2. In the Add Project dialog box, select Setup and Deployment Projects in the Project Type pane, and then choose Setup Project in the Templates pane. In the Name box, type DBCustomAction Installer .
  3. Click OK to close the dialog box.
  4. In the Properties window, select the ProductName property and type DB Installer .
  5. In the File System Editor, select the Application Folder . On the Action menu, choose Add , Project Output .
  6. In the Add Project Output Group dialog box, select the primary output for the DBCustomAction project. Click OK to close the dialog box.

To create a custom installation dialog

  1. Select the DBCustomAction Installer project in Solution Explorer. On the View menu, point to Editor , and choose User Interface .
  2. In the User Interface Editor, select the Start node under Install . On the Action menu, choose Add Dialog .
  3. In the Add Dialog dialog box, select the Textboxes (A) dialog, then click OK to close the dialog box.
  4. On the Action menu, choose Move Up . Repeat until the Textboxes (A) dialog is above the Installation Folder 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 you to specify the name of the database to be created on the database server .
  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 .

To create a custom action

  1. Select the DBCustomAction Installer project in Solution Explorer. On the View menu, point to Editor , and choose Custom Actions .
  2. In the Custom Actions Editor, select the Install node. On the Action menu, choose Add Custom Action .
  3. In the Select item in project dialog box, double-click the Application Folder .
  4. Select the Primary output from DBCustomAction(Active) item, then click OK to close the dialog box.
  5. In the Properties window, select the CustomActionData property and type /dbname=[CUSTOMTEXTA1] .
  6. On the Build menu, choose Build DBCustomActionInstaller.

To install on your development computer

  • Select the DBCustomAction Installer project in Solution Explorer. On the Project menu, choose Install .

    This will run the installer on your development computer.

    Note ???You must have install permissions on the computer in order to run the installer.

To deploy to another computer

  1. In Windows Explorer, navigate to your project directory and find the built 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 on a network, copy the files to traditional media such as CD-ROM.

    On the target computer, double-click the Setup.exe file to run the installer.

    Note ???You must have install permissions on the computer in order to run the installer.

To uninstall the application

  1. In the Windows Control Panel, double-click Add/Remove Programs .
  2. In the Add/Remove Programs dialog box, select DBCustomAction Installer and click Remove , then click OK to close the dialog box.
    Tip ???To uninstall from your development computer, on the Project menu, choose Uninstall .

See Also

Custom Actions Management in Deployment | CustomActionData Property | Connecting to Data Sources with ADO.NET | Error Handling in Custom Actions



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=131479


Using a Custom Action to Create a Database During Installation


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 大色综合色综合资源站 | 亚洲黄色在线视频 | 欧美高清视频一区 | 日本高清色视频在线观看免费 | 亚洲国产一区在线 | 国产精品精品视频 | 成人三级视频 | 极品丝袜高跟91极品系列 | 日本在线观看免费视频 | 91免费在线看 | 激情综合婷婷久久 | 夜夜撸夜夜爽 | 亚洲免费人成在线视频观看 | 欧美精品v国产精品v日韩精品 | 香蕉av777xxx色综合一区 | 黄色影视大全 | 日韩精品一级毛片 | 日韩精品一区二 | 草草线在成年免费视频网站 | 一个看片免费视频www | 午夜精品久久久久久久男人的天堂 | 韩国精品一区二区 | 狠狠色噜噜狠狠狠97影音先锋 | 欧美日韩三级在线观看 | 又黄又爽的网站 | 日本v在线 | 青娱乐免费视频在线观看 | 色婷婷精品综合久久狠狠 | 欧美国产一区二区 | 午夜视频吧 | 国产一区二区三区在线 | 国产在线观看福利 | 日韩18在线观看地址 | 欧洲毛片 | 免费一区二区三区 | 视频在线亚洲 | 精品视频一区二区三区在线观看 | 在线视频不卡国产在线视频不卡 | 国产2区| 日韩成人黄色 | 日韩精品视频一区二区三区 |