Just listening to the SMART Client deployment, in detail, if you run custom DLL or EXE in the .NET installation engineering, how to get the passage of the installation project in the customized project. The following is roughly talking about your own experience: First, it is a class project.
Then add a installation class file and add a sql.txt file, as an embedded resource, the code of the class is as follows: DIM CN AS SQLConnection 'Get SQL Script String Private Function GetSql (Byval Name As String AS STRING TRY 'By reflecting the assembly DIM ASM AS [Assembly] = [assembly] .geTexecutingAsembly ()' Read resource file information, to set resource files to be embedded when compiled DIM SM AS stream = asm .GetManifestResourceStream (Asm.GetName (). Name "." Name) Dim Rr As New StreamReader (Sm) Return Rr.ReadToEnd Catch ex As Exception MsgBox (Err.Description, MsgBoxStyle.OKOnly, "error message") Throw ex End Try End Function 'to give the database backup file path Private Function GetBakFilePath (ByVal DatFileName As String) As String Try' reflected by the information taking into assembly Dim Asm As [assembly] = [assembly] .GetExecutingAssembly () 'read the resource file, To set the resource file to build a embedded resource DIM SM AS stream = asm.getmanifestResourceStream (asm.getname (). Name "." DATFILENAME) IF File.exists ("C: /" & DatFileName) THEN FIL E.DELETE ("C: /" & DatFileName) END IF DIM FS AS NEW FILESTREAM ("C: /" & DatFileName, FileMode.create) DIM SW AS New BinaryWriter (FS) DIM RECBYTE (Sm.Length - 1) AS BYTE DIM STREAD AS New BinaryReader (SM) Strread.Read (Recbyte, 0, Recbyte.Length) SWRITE (Recbyte, 0, Recbyte.Length) sw.close () fs.close () Return "C: /" & DatFileName Catch EX AS Exception MsgBox (Err.Description, MsgboxStyle.okonly, "Error Tips"
) Throw ex End Try End Function Private Sub ExecuteSql (ByVal DbName As String, ByVal SqlText As String, ByVal uid As String, ByVal pwd As String, ByVal servername As String) Dim cmd As New SqlCommand (SqlText, Cn) If Cn.State = ConnectionState.closed the cn.open () try cn.changedatabase (dbname) cmd.executenonquery () Catch exception msgbox ("Run SQL script error!", Msgboxstyle.okonly, "prompt") throw exe Try CN. Close () End Sub Protected Sub AddDBTable (ByVal DBName As String, ByVal uid As String, ByVal pwd As String, ByVal servername As String) 'is determined whether the database exists Try Cn = New SqlConnection ( "Persist Security Info = False; User ID = "& Uid &"; Initial Catalog = Master; Data Source = "& ServerName &"; Password = "& PWD &"; Max Pool Size = 75000 ") DIM DT AS New DataTable () cn open () DIM CMD AS New SqldataAdapter () cmd.selectcommand = ne W SQLCommand ("exec sp_helpdb", cn) cmd.fill (dt) Dim i as int16 for i = 0 to dt.rows.count - 1 if dbname.tolower = ctype (dt.rows (i) .Item (0) , String) .tolower thring in cmd = Nothing cn.close () EXIT SUB End If Next Catch EX AS Exception Msgbox (Err.Description & "Connection Database error, check if the input parameters are correct!", MsgboxStyle. Okonly, "Error Tips") EXIT SUB ', if you already exist, you jump out of the end try
Try '======== Method 1: Run SQL script Create Database' ExecuteSQL ("Master", "Create Database" & Dbname, UID, PWD, ServerName) 'ExecuteSQL (DBNAME, Getsql ("mysql.txt" ), uid, pwd, servername) '======== Method 2: Restore backup file DIM cm as new adod.com () DIM CN As new adod.com () DIM DBRS AS NEW AdoDB.Recordset ) Cn.open ("provider = SQLOLEDB.1; PERSIST security info = false; user id =" & uid & "; infitial catalog = master; data source =" & servername "; password =" & pwd) cm.activeConnection = CN 'Delete whether the data exists, delete cm.commandtext = "exec sp_helpdb" dbrs = cm.execute ()' Take all database name if not dbrs.bof and not dbrs.eof the do while not dbrs.eof if Do While NOT DBRS.EOF Trim (dbrs.fields (0) = trim (dbname) Then 'If the data stock cm.commandtext = "DROP DATABASE" & TRIM (DBNAME) cm.execute () EXIT DO E Nd if DBRS.MOVENEXT () DIM SFILE 'DBRS.CLOSE () DIM SFILE AS STRING = GetBakFilePath ("InstallDb.dat") cm.commandtext = "Restore Database" & Trim (DBNAME) & "from disk ='" & Trim (sfile) & "'"
CM.EXECUTE () cn.close () if file.exists (sfile) THEN FILE.DELETE (SFILE) Endiff (Err.Description & "A", MSGBoxStyle.okonly, "Error Tips") Throw End Try End Sub 'overridden installation method PUBLIC OVERRIDES SUB Install (Byval Stateaver As System.collections.idictionary) MyBase.Install (Stateso)' Take the parameter value DIM Connstr As in the text box added to the user interface in the installer String = me.context.Parameters.item ("dbname") DIM CS AS String () = Split (Connstr, "|") AddDBTable (CS (0), CS (1), CS (2), CS (3) ) End Sub then adds a installation project to add the project of the above class as the project main output. Add a text box in the user interface and enter the parameter name in the four properties of the text box .. Set up four Parameters, when you are running, there will be interfaces that allow you to enter four parameters. On the installation item in the custom operation, you will be set to place the loaded project primary input. And set the attribute CustomActionData to / parameter name = [] [] [] [] ... written in this way to set the parameters in the file box, let's take a look at the code in the above class: DIM Connstr as string = me.context.Parameters.Item (" "") The value of the parameter dbname will be taken to the value of the user to enter the value of the user. The type is also overwritten. It is automatically run, and the user-defined program code. Code and usage The same VBNET. The above code has two cases, one is to get the SQL statement from the embedded text file, run it to create a database. The other is a DAT file with SQL data backup As an embedded resource, during the installation process, the parameters entered by the user are condition, connected to the SQL server and restore the database ...