Production .NET installation project

xiaoxiao2021-03-05  21

1. Add a new item-> Select Class Library Template -> Named DBCustomAction 2, click Project Right-click -> Add New Item -> Select Installer class (named dbcustomaction.cs) 3, add it in Server Explorer -> Connect to Database -> Specify user password (Select Allow Save Password) -> Database Select Master 4 to switch to DBCustomAction.cs -> Drag Master.dbo in Server Explorer Database Connections to Designer 5, add a new item SQL.txt (Note To use lowercase), enter the following SQL code CREATE TABLE [DBO]. [MK_EMPLOYEES] ([Name] [char] (30) Collate SQL_LATIN1_GENERAL_CP1_CI_AS NOT NULL, [RSVP] [int] NULL, [REQUESTS] [NVARCHAR] (4000) Collate SQL_LATIN1_GENER_CP1_CI_AS NULL) ON [PRIMARY];

Alter Table [DBO]. [Mk_employees] with nocheck address [pk_mk_employees] Primary Key Clustered ([Name]) on [primary]; (P.s: You can also export directly with SQLServer)

6, in SQL.txt's right-click Properties -> Generate Operation -> Embedded Resources 7, switch dbcustomaction.cs to code view, add the following code string getsql (string name) {try {ask {ask {ask {ask {ask gSEMBLY ASM = askEMBLY.GETEXECUTINAMBLY ); Stream strm = Asm.GetManifestResourceStream (Asm.GetName () Name Name). "."; StreamReader reader = new StreamReader (strm); return reader.ReadToEnd ();} catch (Exception ex) {Console.Write ("In getsql:" ex. amount); throw ex;}}

Private Void ExecuteSQL (String DatabaseName, String SQL) {system.data.sqlclient.sqlcommand command = new system.data.sqlclient.sqlcommand (SQL, SqlConnection1);

Command.connection.open (); command.connection.changedatabase (DatabaseName); try {command.executenonQuery ();} finally {command.connection.close ();}}

protected void AddDBTable (string strDBName) {try {ExecuteSql ( "master", "CREATE DATABASE" strDBName); ExecuteSql (strDBName, GetSql ( "sql.txt"));} catch (Exception ex) {Console.Write ( " In exception handler: " ex.Message);}} public override void Install (System.Collections.IDictionary stateSaver) {base.Install (stateSaver); AddDBTable (this.Context.Parameters [" dbname "]);}

8, add a new project, (Select Add to Solution) -> Project Type to Installing Items -> Named DBCustomAction Installer 9, select Application Folder -> Add -> Project Output -> Main Output 10, Solution Explorer -> Right click on the item (DBCustomAction Installer) -> View -> User Interface 11, Select the Start Node -> Add Dialog -> Text A 12, Select Text Box A-> Right Key -> Top 13, select text box A properties -> Modify Bannertext, (Specify Database Name) 14, modify BodyText (this Dialog Allows You to Specify On The Database Server.) 15, modify Editlabel1 (Name of DB), modify edit1porperty (CustomTexta1), set other Edit 2, 3, 4 EDIT (2, 3, 4) Visible attribute to false; 16, in the program resource manager -> Right click Install item (DBCustomaction Installer ) -> View -> Custom operation 17, select the installation node -> Add -> Double-click Application Folder -> Main Output from DBCustomAction (Event) -> Right click Properties -> CustomactiveData property modified to / dbname = [CustomTexta1] 18, compile generation, OK!

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

New Post(0)