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

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

新聞中心

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

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

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

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

2. 將安裝文件LisenceFile.rtf添加到“Test Installer”項目

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

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

將代碼添加到安裝程序類中,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 "組件設計器生成的代碼 "  
  15.  
  16. public Sub New()Sub New()  
  17.  
  18. mybase.new()  
  19.  
  20. '該調(diào)用是組件設計器所必需的  
  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 語句  
  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安裝部署代碼實現(xiàn)建立數(shù)據(jù)庫------------  
  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ù)庫名稱建立數(shù)據(jù)庫  
  98.  
  99. executesql(connstr, "master",   
  100. "CREATE DATABASE " + Me.Context.Parameters.Item("dbname"))  
  101.  
  102. 'ASP.NET安裝部署代碼實現(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安裝部署代碼實現(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安裝部署代碼實現(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("沒有找到配置文件")  
  149.  
  150. end If  
  151.  
  152. '實例化xml文檔  
  153.  
  154. dim XmlDocument As New System.Xml.XmlDocument  
  155.  
  156. xmldocument.load(fileinfo.fullname)  
  157.  
  158. '查找到appsettings中的節(jié)點  
  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安裝部署代碼實現(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 文件沒有包含connString連接字符串設置")  
  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 

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

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

***編譯生成!如圖:

安裝界面:如圖

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


本文名稱:ASP.NET安裝部署代碼實現(xiàn)
文章地址:http://m.5511xx.com/article/cojgpcs.html