网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 论文素材 设计下载 最新论文 下载排行 论文上传 在线投稿 联系我们
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > C# > 正文
.NET平台下WEB应用程序的部署(安装数据库和自动配置)
来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/14
下载{$ArticleTitle}原创论文样式
ll(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

最后编译生成!

安装界面:


说明:本文版权与解释权归李洪根所有,如需转载,请保留完整的内容及此声明。


QQ: 21177563 MSN: lihonggen@hotmail.com
 

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号