日期:2014-05-19  浏览次数:20458 次

求net打包自动安装数据库的问题!!!!!!!
做了一个asp.net网站,经理让我把它做成安装文件,而且还要把数据库打包进去,我也去查过资料,但是都是应用程序的打包问题,很少有关于.net2005的网站安装步骤,请各位帮忙,能有例子的话就更好,谢谢了!对了,用的是mssql2000。
-------在线等!

------解决方案--------------------
一般都是安装的时候执行Sql脚本文件吧
------解决方案--------------------
在贴子中可以找到。安装制作类:
Imports System.ComponentModel

Imports System.Configuration.Install

Imports System.IO

Imports System.Reflection



<RunInstaller(True)> Public Class DBCustomAction

Inherits System.Configuration.Install.Installer



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

Public Sub New()

MyBase.New()

'该调用是组件设计器所必需的

InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

' Installer 重写 dispose 以清理组件列表。

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

Private components As System.ComponentModel.IContainer

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

#End Region

'执行SQL 语句

Private Sub ExecuteSql(ByVal conn As String, ByVal DatabaseName As String, ByVal Sql As String)

Dim mySqlConnection As New SqlClient.SqlConnection(conn)

Dim Command As New SqlClient.SqlCommand(Sql, mySqlConnection)

Command.Connection.Open()

Command.Connection.ChangeDatabase(DatabaseName)

Try

Command.ExecuteNonQuery()

Finally

'Close Connection

Command.Connection.Close()

End Try

End Sub

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

' ------------------------建立数据库-------------------------------------------------

Try

Dim connStr As String = String.Format( "data source={0};user id={1};password={2};persist security info=false;packet size=4096 ", Me.Context.Parameters.Item( "server "), Me.Context.Parameters.Item( "user "), Me.Context.Parameters.Item( "pwd "))

'根据输入的数据库名称建立数据库

ExecuteSql(connStr, "master ", "CREATE DATABASE " + Me.Context.Parameters.Item( "dbname "))

'调用osql执行脚本

Dim sqlProcess As New System.Diagnostics.Process

sqlProcess.StartInfo.FileName = "osql.exe "

sqlProcess.StartInfo.Arguments = String.Format( " -U {0} -P {1} -d {2} -i {3}db.sql ", Me.Context.Parameters.Item( "user "), Me.Context.Parameters.Item( "pwd "), Me.Context.Parameters.Item( "dbname "), Me.Context.Parameters.Item( "targetdir "))

sqlProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden

sqlProcess.Start()

sqlProcess.WaitForExit() '等待执行

sqlProcess.Close()

'删除脚本文件

Dim sqlF