In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how to analyze VB. NET installation project specific application methods, the content is very detailed, interested friends can refer to, hope to help everyone.
VB. NET is a powerful object-oriented programming language developed by Microsoft. It can help us create a safe and stable programming environment and improve programming efficiency. In this article, we will introduce the concepts related to VB. NET installation project in detail.
Just listened to the SMART CLIENT deployment lecture, which describes in detail if the VB. NET installation project running custom DLL or EXE, later in the custom project how to get the installation project passed parameters. Below is a brief description of your own experience:
First, create a class project. Then add an installation class file and add an SQL.TXT file as an embedded resource. The class code is as follows, explained later:
Dim Cn As SqlConnection
'Get SQL script string
Private Function GetSql(ByVal Name As String) As String
Try
'Fetch assembly by reflection
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()
'Read resource file data, to set resource file to embedded resource at compile time
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 Prompt")
Throw ex
End Try
End Function
'Get database backup file path
Private Function GetBakFilePath
(ByVal DatFileName As String) As String
Try
'Fetch assembly by reflection
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()
'Read resource file data, to set resource file to embedded resource at compile time
Dim Sm As Stream = Asm.GetManifestResourceStream
(Asm.GetName().Name + ". " + DatFileName)
If File.Exists("c:\" & DatFileName) Then
File.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 strread As New BinaryReader(Sm)
strread.Read(recbyte, 0, recbyte.Length)
Sw.Write(recbyte, 0, recbyte.Length)
Sw.Close()
Fs.Close()
Return "C:\" & DatFileName
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.OKOnly, "Error Prompt")
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 Then Cn.Open()
Try
Cn.ChangeDatabase(DbName)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox("Error running SQL script! ", MsgBoxStyle.OKOnly, " Prompt ")
Throw ex
End Try
Cn.Close()
End Sub
Protected Sub AddDBTable(ByVal DBName As String,
ByVal uid As String, ByVal pwd As String, ByVal servername As String)
'Determine if 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 = New 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 Then
'Database exists
cmd = Nothing
Cn.Close()
Exit Sub
End If
Next
Catch ex As Exception
MsgBox(Err.Description & "Error connecting database, please check whether the parameters entered are correct! ",
MsgBoxStyle.OKOnly, "Error Tips")
Exit Sub 'If it already exists, exit
End Try
Try
'====== Method 1: Run SQL script to create database
' ExecuteSql("Master", "Create DataBase " & DBName, uid, pwd, servername)
'ExecuteSql(DBName, GetSql("mysql.txt"), uid, pwd, servername)
'====== Method 2: Perform Restore of Backup Files
Dim cm As New ADODB.Command()
Dim cn As New ADODB.Connection()
Dim dbrs As New ADODB.Recordset()
cn.Open("Provider=SQLOLEDB.1;Persist Security Info=False;
User ID=" & uid & ";Initial Catalog=master;
Data Source=" & servername & ";password=" & pwd)
cm.ActiveConnection = cn
'Determine if the data exists, delete if it exists
cm.CommandText = "exec sp_helpdb"
dbrs = cm.Execute() 'takes all database names
If Not dbrs.BOF And Not dbrs.EOF Then
Do While Not dbrs.EOF
If Trim(dbrs.Fields(0).Value) = Trim(DBName) Then 'if the data is in stock
cm.CommandText = "drop database " & Trim(DBName)
cm.Execute()
Exit Do
End If
dbrs.MoveNext()
Loop
End If
' 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)
End If
Catch ex As Exception
MsgBox(Err.Description & "A", MsgBoxStyle.OKOnly, "Error Prompt")
Throw ex
End Try
End Sub
'Overwrite installation method
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
'Get parameter values from text boxes added back to the user interface in the installer
Dim Connstr As String = Me.Context.Parameters.Item("dbname")
Dim Cs As String() = Split(Connstr, "|")
AddDBTable(Cs(0), Cs(1), Cs(2), Cs(3))
End Sub
Then add a VB. NET installation project, adding the above class project as the main output of the project. Add a text box to the user interface
VB. NET Control Automatic Sorting Related Code Sample Guide
VB. NET queries contain powerful
VB. NET extension method concept detailed explanation
Basic Concept Analysis of Local Variable Type Inference in VB. NET
Conceptual Analysis of VB. NET Object Sequence Script
Then enter parameter names in the four properties of the text box..
There are four parameters set here. When the installation is running, there will be an interface for you to enter four parameters. On the installation project in the custom operation, select the main input of the loaded project.
and set the attribute CustomActionData to/Parameter Name =[][][]... To write the parameters set in the file box in this way, let's look at the code in the above class:
Dim Connstr As String = Me.Context.Parameters.Item("dbname")
The dbname parameter will be taken, which is the value that the user enters in the installation interface.
The Install method is also overridden in the class. Will automatically run and execute user-defined program code. Code and usually compiled by the same vbNET.
The VB. NET installation code above does two things. One is to get SQL statements from embedded text files and run them to create databases. Another is to use SQL data backup DAT file as embedded resources, in the installation process, parameters entered by the user for the condition, connect SQL server and restore the database.
About how to analyze VB. NET installation project specific application methods to share here, I hope the above content can have some help for everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.