建立一個連接數據庫的VB組件

發表于:2007-07-14來源:作者:點擊數: 標簽:
首先在你的config.web 文件中創建以下參數: appsettings add key=gConn value=server=local;uid=sa;pwd=secret;database=pubs / /appsettings 接著建立dbConn. vb 文件。 Imports System Imports System.Web Imports System.Collections Namespace WebDB Pu
首先在你的config.web 文件中創建以下參數:
<appsettings>
<add key="gConn" value="server=local;uid=sa;pwd=secret;database=pubs" />
</appsettings>

接著建立dbConn.vb 文件。
Imports System
Imports System.Web
Imports System.Collections

Namespace WebDB
Public Class WebDBconn
Shared m_ConnectionString As String
Shared ReadOnly Property ConnectionString As String

Get
If m_ConnectionString = "" Then

Dim appsetting As Hashtable = CType(HttpContext.Current.GetConfig("appsettings"), Hashtable)
'使用 config.web 中設立好的連接字符串
m_ConnectionString = CStr(appsetting("DBConnString"))

If m_ConnectionString = "" Then
throw new Exception("Dtabase Connection Value not set in Config.web")
End if

End If

' 返回連接字符串
return m_connectionString

End Get
End Property
End Class
End Namespace

'下面編譯dll文件:創建一個批處理文件, 命名為 MakeDll.bat ,存放在dbConn.vb 相同的目錄,其中的內容如下
set odir=dbConn.dll
set assemblies=System.Web.dll
vbc /t:library /out:%odir% /r:%assemblies% dbConn.vb
執行批處理文件, 將 dbconn.dll 拷貝到你的WEB 目錄的 BIN 目錄下并創建如下的.aspx 文件:

<%@ Page Description="ASP+ document" EnableSessionState="false" MaintainState="false" %>
<%@ Import Namespace="WebDB" %>
<script language="VB" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

response.write(WebDBconn.ConnectionString)

End Sub

</script>

<html>
<head>
<title></title>
</head>
<body>
</body>
</html> 

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97