精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程
返回建站学首页
导航:
建站首页 | 网站设计 | 网站开发 | 网站运营 | 网页软件 | 建站指南 | 搜索优化 | 图像处理 | 视频教程 | 书籍教程 | 建站专题
当前位置:首页>网站开发>asp.net教程>正文

.NET平台下WEB应用程序的部署的例子


来源:不详 时间:07-03-21 点击: 点击这里收藏本文

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 sqlFileInfo As New System.IO.FileInfo(String.Format("{0}db.sql", Me.Context.Parameters.Item("targetdir")))

if sqlFileInfo.Exists Then

sqlfileinfo.delete()

end If

catch ex As Exception

throw ex

end Try

 

' ---------------------将连接字符串写入Web.config-----------------------------------

try

dim FileInfo As System.IO.FileInfo = New System.IO.FileInfo(Me.Context.Parameters.Item("targetdir") & "\web.config")

if Not FileInfo.Exists Then

throw New InstallException("没有找到配置文件")

end If

'实例化xml文档

dim XmlDocument As New System.Xml.XmlDocument

xmldocument.load(fileinfo.fullname)

 

'查找到appsettings中的节点

dim Node As System.Xml.XmlNode

dim FoundIt As Boolean = False

for Each Node In XmlDocument.Item("configuration").Item("appSettings")

if Node.Name = "add" Then

if Node.Attributes.GetNamedItem("key").Value = "connString" Then

'写入连接字符串

node.attributes.getnameditem("value").value = String.Format("Persist Security Info=False;Data Source={0};Initial Catalog={1};User ID={2};Password={3};Packet Size=4096;Pooling=true;Max Pool Size=100;Min Pool Size=1", _

me.context.parameters.item("server"), Me.Context.Parameters.Item("dbname"), Me.Context.Parameters.Item("user"), Me.Context.Parameters.Item("pwd"))

foundit = True

end If

end If

next Node

if Not FoundIt Then

throw New InstallException("web.Config 文件没有包含connString连接字符串设置")

end If

xmldocument.save(fileinfo.fullname)

catch ex As Exception

throw ex

end Try

end Sub

end Class

最后编译生成!

9 7 3 1 2 4 8 :

  把此文章收藏到:          
广而告之
文章搜索
  • Google JZxue.Com

关于我们 | 联系我们 | 友情链接 | 网站地图
Copyright © 2005 - 2006 建站学 All rights reserved.