<iframe align="top" marginwidth="0" marginheight="0" src="http://www.zealware.com/46860.html" frameborder="0" width="468" scrolling="no" height="60"></iframe>
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.
NoteThis walkthrough requires SQL Server on the computer where you will deploy the application.
To create an installer class
- On the File menu, point to New, and then choose Project.
- 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.
- Click OK to close the dialog box.
- On the Project menu, choose Add New Item.
- In the Add New Item dialog box, choose Installer Class. In the Name box, type DBCustomAction.
- Click OK to close the dialog box.
To create a data connection object
- In Server Explorer, select Data Connections. Right-click and choose Add Connection.
- In the Data Link Properties dialog box, do the following:
- Enter the server name.
- Select Use Windows NT Integrated Security.
- In the database box, type master.
- Click OK to close the dialog box.
- 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
- In Solution Explorer, select the DBCustomAction project. On the Project menu, choose Add New Item.
- In the Add New Item dialog box, choose Text File. In the Name box, type sql.txt (must be in lower case).
- Click OK to close the dialog box.
- 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];
- 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
- In Solution Explorer, select DBCustomAction.vb. On the View menu, choose Code.
- Add the following Imports statement at the top of the module:
Imports System.IOImports System.Reflection
- 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
- On the Build menu, choose Build DBCustomAction.
To create a deployment project
- On the File menu, choose Add Project, New Project.
- 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.
- Click OK to close the dialog box.
- In the Properties window, select the ProductName property and type DB Installer.
- In the File System Editor, select the Application Folder. On the Action menu, choose Add, Project Output.
- 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
- Select the DBCustomAction Installer project in Solution Explorer. On the View menu, point to Editor, and choose User Interface.
- In the User Interface Editor, select the Start node under Install. On the Action menu, choose Add Dialog.
- In the Add Dialog dialog box, select the Textboxes (A) dialog, then click OK to close the dialog box.
- On the Action menu, choose Move Up. Repeat until the Textboxes (A) dialog is above the Installation Folder node.
- In the Properties window, select the BannerText property and type Specify Database Name.
- Select the BodyText property and type This dialog allows you to specify the name of the database to be created on the database server.
- Select the Edit1Label property and type Name of DB:.
- Select the Edit1Property property and type CUSTOMTEXTA1.
- Select the Edit2Visible, Edit3Visible, and Edit4Visible properties and set them to false.
To create a custom action
- Select the DBCustomAction Installer project in Solution Explorer. On the View menu, point to Editor, and choose Custom Actions.
- In the Custom Actions Editor, select the Install node. On the Action menu, choose Add Custom Action.
- In the Select item in project dialog box, double-click the Application Folder.
- Select the Primary output from DBCustomAction(Active) item, then click OK to close the dialog box.
- In the Properties window, select the CustomActionData property and type /dbname=[CUSTOMTEXTA1].
- On the Build menu, choose Build DBCustomActionInstaller.
To install on your development computer
To deploy to another computer
- 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.
- Copy the DBCustomAction Installer.msi file and all other files and subdirectories in the directory to another computer.
NoteTo 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.
NoteYou must have install permissions on the computer in order to run the installer.
To uninstall the application
- In the Windows Control Panel, double-click Add/Remove Programs.
- In the Add/Remove Programs dialog box, select DBCustomAction Installer and click Remove, then click OK to close the dialog box.
TipTo 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
分享到:
相关推荐
How to Create a Database in Python using SQL Lite 3 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Using Labview To Create Multithreaded Vis
How to Create a Database in Python using SQL Lite 3 英文mobi 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
How to create a database in python using sql lite 3.pdf
How to Create a Database in Python using SQL Lite 3 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
How to Create a Database in Python using SQL Lite 3 英文无水印转化版pdf pdf所有页面使用FoxitReader、PDF-XChangeViewer、SumatraPDF和Firefox测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或...
How To Automate Excel to Create And Format a New Workbook Using C++ .NET and MFC
With eye-opening examples of real-world projects, Design Elements, Using Images to Create Graphic Impact is filled with valuable tips and practical strategies for using imagery to create memorable and...
Simple program demonstrating how to create a stop watch using the Timer control.
I have tried to create a circular command button like thing (using just shapes).
Zip Code Database Is A Program To Find Zip Codes By Using A Lookup Field.
Learn to build e-commerce sites using PHP by installing a server using WAMP, configuring MySQL for your product database, creating your product database and tables, and writing the required ...
Oracle数据库开发英文原版书,内容广泛,结构清楚,是当下流行的数据库开发指导书。
Beginning SVG: A Practical Introduction to SVG using Real-World Examples By 作者: Alex Libby ISBN-10 书号: 1484237595 ISBN-13 书号: 9781484237595 Edition 版本: 1st ed. 出版日期: 2018-09-07 pages 页数:...
In this chapter you’ll learn how to override model defaults to create custom accessors and mutators, add instance methods, and use scopes to easily filter database results with minimal code ...
How to create database and database applications using iOS and Swift How to insert, select, edit, and delete records How to extend SQLite How to work with multi-database apps How to use SQLite with ...
SPICE A Guide to Circuit Simulation and Analysis using pspice.pdf
This essay gives a demonstration of creating DB2 user function easily by DB Query Analyzer. And also the creating process of stored procedure has no difference with that of function What’s more, the ...
• Using Parallel LINQ to Objects (PLINQ) to optimize queries for multi-core processors, and how to build custom parallel query operators • Integrating the best LINQ to Objects patterns into your day...