About the engineering band database package (1)

zhaozj2021-02-16  64

Many friends have encountered such a problem: how the project is packaged in the database. The following briefly explain MSDN documentation on this issue: URL: http: //msdn.microsoft.com/library/default.asp url = / library / en-us / vsintro7 / html / vxwlkWalkthroughUsingCustomActionToCreateDatabaseDuringInstallation.asp?

The full text is as follows: Copy from MSDN.

"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "

USING a Custom Action To Create A Database DURING Installation:

The Following Walkthrough Demonstrates The Use of a Custom Action and The CustomactData 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 The THEEN CLASS LIBRARY 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:

ENTER The Server Name.

b. Select Use Windows NT Integrated Security.

c. in The Database Box, Type Master.

D. 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:

5. CREATE TABLE [DBO]. [Employees] (

6. [Name] [25) Collate SQL_LATIN1_GENERAL_CP1_CI_AS NOT NULL,

7. [RSVP] [INT] NULL,

8. [Requests] [NVARCHAR] (4000) Collate SQL_LATIN1_GENERAL_CP1_CI_AS NULL

9.) on [primary];

10.

11. Alter Table [DBO]. [Employees] with nocheck add

12. Constraint [PK_EMPLOYEES] Primary Key Clustered

13. (

14. [Name]

) On [primary];

15. 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:

3. Imports System.io

Imports system.reflection

4. Add The Following Code to the Class:

5. Private function getSql (Byval Name As String) AS STRING

6. TRY

7.

8. 'Gets the current assembly.

9. DIM ASM AS [Assembly] = [assembly] .getexecutingassembly ()

10.

11. 'Resources Are Named Using A Fully Qualified Name.

12. DIM STRM AS stream = asm.getmanifestResourceStream (asm.getname (). Name "." Name)

13.

14. 'Reads The Contents of The Embedded File.

15. Dim Reader As StreamReader = New StreamReader (STRM) 16. Return Reader.ReadToend ()

17. Catch EX AS EXCEPTION

18. MsgBox ("in getsql:" & ex.Message)

19. THROW EX

20. End Try

twenty one.

22. End Function

twenty three.

24. Private Sub ExecuteSQL (Byval DatabaseName As String, Byval SQL AS String)

25. DIM Command As New Sqlclient.sqlcommand (SQL, SQLCONNECTION1)

26.

27. Command.connection.Open ()

28. Command.Connection.changeDatabase (DatabaseName)

29. TRY

30. Command.executenonQuery ()

31. Finally

32. 'Finally, Blocks Are A Great Way To Ensure That The Connection

33. 'Is always closed.

34. Command.connection.Close ()

35. End Try

36. End Sub

37.

38. Protected sub adddbtable (byval strDbname as string)

39. TRY

40. 'Creates the Database.

41. ExecuteSQL ("Master", "Create Database" StrDBName)

42.

43. 'Creates the Tables.

44. ExecuteSQL (strDbname, getsql ("sql.txt")))

45.

46. ​​Catch EX AS Exception

47. 'Reports Any Errors and Abort.

48. MsgBox ("in Exception Handler:" & ex.Message)

49. THROW EX

50. End Try

51. End Sub

52.

53. Public overrides sub install (Byval Stateaver as system.collections.idictionary)

54. MyBase.Install (Stateaver)

55. adddbtable (me.context.parameters.Item ("dbname"))

End Sub

56. On the build menu, choield dbcustomaction.

To create a Deployment Project 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 Underl. On the action menu, choose add dialog.

3. In The Add Dialog Dialog Box, Select The TextBoxes (a) Dialog, The 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, The 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 Subdirector 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 Program.

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.

"" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

转载请注明原文地址:https://www.9cbs.com/read-25469.html

New Post(0)