日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
ASP.NET安裝部署代碼實(shí)現(xiàn)

ASP.NET安裝部署代碼實(shí)現(xiàn)之添加文件簡(jiǎn)介:

創(chuàng)新互聯(lián)建站服務(wù)項(xiàng)目包括翁牛特網(wǎng)站建設(shè)、翁牛特網(wǎng)站制作、翁牛特網(wǎng)頁(yè)制作以及翁牛特網(wǎng)絡(luò)營(yíng)銷策劃等。多年來(lái),我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,翁牛特網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到翁牛特省份的部分城市,未來(lái)相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

1. 將SQL Server生成的腳本文件db.sql添加到“Test Installer”項(xiàng)目

2. 將安裝文件LisenceFile.rtf添加到“Test Installer”項(xiàng)目

3. 在用戶界面編輯器中,選擇許可協(xié)議,設(shè)置LisenceFile屬性為L(zhǎng)isenceFile.rtf文件

以下的ASP.NET安裝部署代碼實(shí)現(xiàn)是整個(gè)部署的最重要的一部分了

將代碼添加到安裝程序類中,dbcustomaction.vb類

 
 
 
 
  1. Imports System.ComponentModel  
  2.  
  3. imports System.Configuration.Install  
  4.  
  5. imports System.IO  
  6.  
  7. imports System.Reflection  
  8.  
  9. ﹤runinstaller(true)﹥ Public Class DBCustomActionClass DBCustomAction  
  10.  
  11. inherits System.Configuration.Install.Installer  
  12.  
  13.  
  14. #region "組件設(shè)計(jì)器生成的代碼 "  
  15.  
  16. public Sub New()Sub New()  
  17.  
  18. mybase.new()  
  19.  
  20. '該調(diào)用是組件設(shè)計(jì)器所必需的  
  21.  
  22. initializecomponent()  
  23.  
  24. '在 InitializeComponent() 調(diào)用之后添加任何初始化  
  25.  
  26. end Sub  
  27.  
  28. ' Installer 重寫 dispose 以清理組件列表。  
  29.  
  30. protected Overloads Overrides Sub Dispose()Sub Dispose(ByVal disposing As Boolean)  
  31.  
  32. if disposing Then  
  33.  
  34. if Not (components Is Nothing) Then  
  35.  
  36. components.dispose()  
  37.  
  38.  end If  
  39.  
  40. end If  
  41.  
  42. mybase.dispose(disposing)  
  43.  
  44. end Sub  
  45.  
  46. private components As System.ComponentModel.IContainer  
  47.  
  48. ﹤system.diagnostics.debuggerstepthrough()﹥   
  49. Private Sub InitializeComponent()Sub InitializeComponent()  
  50.  
  51. end Sub  
  52.  
  53. #end Region  
  54.  
  55. '執(zhí)行sql 語(yǔ)句  
  56.  
  57. private Sub ExecuteSql()Sub ExecuteSql(ByVal conn As String,   
  58. ByVal DatabaseName As String, ByVal Sql As String)  
  59.  
  60. dim mySqlConnection As New SqlClient.SqlConnection(conn)  
  61.  
  62. dim Command As New SqlClient.SqlCommand(Sql, mySqlConnection)  
  63.  
  64. command.connection.open()  
  65.  
  66. command.connection.changedatabase(databasename)  
  67.  
  68. try 
  69.  
  70. command.executenonquery()  
  71.  
  72. finally 
  73.  
  74. 'close Connection  
  75.  
  76. command.connection.close()  
  77.  
  78. end Try  
  79.  
  80. end Sub  
  81.  
  82. public Overrides Sub Install()Sub Install(ByVal stateSaver   
  83. As System.Collections.IDictionary)  
  84. MyBase.Install(stateSaver)  
  85.  
  86. ' ----------ASP.NET安裝部署代碼實(shí)現(xiàn)建立數(shù)據(jù)庫(kù)------------  
  87.  
  88. try 
  89.  
  90. dim connStr As String = String.Format("data source={0};  
  91. user id={1};password={2};  
  92. persist security info=false;packet size=4096",   
  93. Me.Context.Parameters.Item("server"),   
  94. Me.Context.Parameters.Item("user"),   
  95. Me.Context.Parameters.Item("pwd"))  
  96.  
  97. '根據(jù)輸入的數(shù)據(jù)庫(kù)名稱建立數(shù)據(jù)庫(kù)  
  98.  
  99. executesql(connstr, "master",   
  100. "CREATE DATABASE " + Me.Context.Parameters.Item("dbname"))  
  101.  
  102. 'ASP.NET安裝部署代碼實(shí)現(xiàn)之調(diào)用osql執(zhí)行腳本  
  103.  
  104. dim sqlProcess As New System.Diagnostics.Process  
  105.  
  106. sqlprocess.startinfo.filename = "osql.exe " 
  107.  
  108. sqlprocess.startinfo.arguments = String.Format(" -U {0} -P {1} -d {2} -i {3}db.sql",   
  109. Me.Context.Parameters.Item("user"), Me.Context.Parameters.Item("pwd"),   
  110. Me.Context.Parameters.Item("dbname"), Me.Context.Parameters.Item("targetdir"))  
  111.  
  112. sqlprocess.startinfo.windowstyle = ProcessWindowStyle.Hidden  
  113.  
  114. sqlprocess.start()  
  115.  
  116. sqlprocess.waitforexit() '等待執(zhí)行  
  117.  
  118. sqlprocess.close()  
  119.  
  120. 'ASP.NET安裝部署代碼實(shí)現(xiàn)之刪除腳本文件  
  121.  
  122. dim sqlFileInfo As New System.IO.FileInfo(String.Format("{0}db.sql",   
  123. Me.Context.Parameters.Item("targetdir")))  
  124.  
  125. if sqlFileInfo.Exists Then  
  126.  
  127. sqlfileinfo.delete()  
  128.  
  129. end If  
  130.  
  131. catch ex As Exception  
  132.  
  133. throw ex  
  134.  
  135. end Try  
  136.  
  137.  
  138.  
  139. ' -ASP.NET安裝部署代碼實(shí)現(xiàn)之將連接字符串寫入Web.config--  
  140.  
  141. try 
  142.  
  143. dim FileInfo As System.IO.FileInfo = New System.IO.  
  144. FileInfo(Me.Context.Parameters.Item("targetdir") & "\web.config")  
  145.  
  146. if Not FileInfo.Exists Then  
  147.  
  148. throw New InstallException("沒(méi)有找到配置文件")  
  149.  
  150. end If  
  151.  
  152. '實(shí)例化xml文檔  
  153.  
  154. dim XmlDocument As New System.Xml.XmlDocument  
  155.  
  156. xmldocument.load(fileinfo.fullname)  
  157.  
  158. '查找到appsettings中的節(jié)點(diǎn)  
  159.  
  160. dim Node As System.Xml.XmlNode  
  161.  
  162. dim FoundIt As Boolean = False  
  163.  
  164. for Each Node In XmlDocument.Item("configuration").Item("appSettings")  
  165.  
  166. if Node.Name = "add" Then  
  167.  
  168. if Node.Attributes.GetNamedItem("key").Value = "connString" Then  
  169.  
  170. 'ASP.NET安裝部署代碼實(shí)現(xiàn)之寫入連接字符串  
  171.  
  172. node.attributes.getnameditem("value").value = String.  
  173. Format("Persist Security Info=False;Data Source={0};  
  174. Initial Catalog={1};User ID={2};Password={3};  
  175. Packet Size=4096;Pooling=true;Max Pool Size=100;  
  176. Min Pool Size=1", _  
  177.  
  178. me.context.parameters.item("server"),   
  179. Me.Context.Parameters.Item("dbname"),   
  180. Me.Context.Parameters.Item("user"),   
  181. Me.Context.Parameters.Item("pwd"))  
  182.  
  183. foundit = True  
  184.  
  185. end If  
  186.  
  187. end If  
  188.  
  189. next Node  
  190.  
  191. if Not FoundIt Then  
  192.  
  193. throw New InstallException("web.Config 文件沒(méi)有包含connString連接字符串設(shè)置")  
  194.  
  195. end If  
  196.  
  197. xmldocument.save(fileinfo.fullname)  
  198.  
  199. catch ex As Exception  
  200.  
  201. throw ex  
  202.  
  203. end Try  
  204.  
  205. end Sub  
  206.  
  207. end Class 

有點(diǎn)難度的就是那個(gè)Process類,它調(diào)用了osql.exe程序,來(lái)執(zhí)行sql語(yǔ)句osql -U,-P,,-d,-i。

web.config的修改代碼是利用xml的語(yǔ)法實(shí)現(xiàn)。不是很難理解。

***編譯生成!如圖:

安裝界面:如圖

ASP.NET安裝部署代碼實(shí)現(xiàn)的基本情況就向你介紹到這里,希望對(duì)你學(xué)習(xí)ASP.NET安裝部署有所幫助。


新聞標(biāo)題:ASP.NET安裝部署代碼實(shí)現(xiàn)
網(wǎng)頁(yè)網(wǎng)址:http://www.5511xx.com/article/cojgpcs.html