vs2010 打包mysql_VS2010(英文版)打包部署自动安装数据库

七).”InstallDB”安装程序类代码(vb.net)

Imports System.ComponentModel

Imports System.Configuration.Install

Imports System.Collections.Generic

Imports System

Imports System.Data

Imports System.Data.SqlClient

Namespace InstallDB

Partial Public Class InstallerDB

Inherits Installer

''' ''' 必须的设计器变量

'''

''' 2011-4-27 10:20 by dan

Private components As System.ComponentModel.IContainer = Nothing

''' ''' 构造函数

'''

''' 2011-4-27 10:20 by dan

Public Sub New()

MyBase.New()

'This call is required by the Component Designer.

InitializeComponent()

'Dim state As System.Collections.IDictionary = New Hashtable

'Add initialization code after the call to InitializeComponent

End Sub

''' ''' 清理所有正在使用的资源

'''

''' 2011-4-27 10:20 by dan

Protected Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not IsNothing(components) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

#Region "组件设计器生成的代码"

''' ''' 设计器支持所需的方法——不要使用代码编辑器修改此方法的内容

'''

'''

Private Sub InitializeComponent()

components = New System.ComponentModel.Container

End Sub

#End Region

#Region "数据库文件为mdf和ldf文件"

''' ''' 附加数据库的mdf文件和ldf文件

'''

''' sql语句

''' 数据名

''' mdf文件名

''' ldf文件名

''' 2011-4-27 15:57 by dan

Private Sub CreateDataBase(ByVal strSql As String, ByVal DataName As String, ByVal strMdf As String, ByVal strLdf As String, ByVal path As String)

'附加数据库

Dim str As String

Dim myConn As SqlConnection = New SqlConnection(strSql)

str = "EXEC sp_attach_db @dbname='" & DataName & "',@filename1='" & strMdf & "',@filename2='" & strLdf & "'"

Dim myCommand As SqlCommand = New SqlCommand(str, myConn)

myConn.Open()

myCommand.ExecuteNonQuery()

myConn.Close()

End Sub

''' ''' 重写安装代码

'''

'''

''' 2011-5-7 18:46 by dan

Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)

MyBase.Install(stateSaver)

Dim server As String = Me.Context.Parameters("server")

Dim uid As String = Me.Context.Parameters("user")

Dim pwd As String = Me.Context.Parameters("pwd")

Dim path As String = Me.Context.Parameters("targetdir")

'连接sql

Dim strSql As String = "server=" & server & ";uid=" & uid & ";pwd=" & pwd & ";database=master"

Dim DataName As String = "BookManage"

Dim strMdf As String = path & "/BookManage_Data.mdf"

Dim strLdf As String = path & "/BookManage_Log.ldf"

Me.CreateDataBase(strSql, DataName, strMdf, strLdf, path)

End Sub

#End Region

End Class

End Namespace

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值