0
FS_Setting是有連接的所有詳細信息的VB類,即:如何獲得SQL連接
Public Class FS_Setting
Public Function Get_RS_Connection() As SqlConnection
Try
Get_RS_Connection = New SqlConnection("Data Source=***********;User ID=sa;Password=*****;database=*********")
Catch ex As System.Exception
Throw New System.Exception("Get_RS_Connection Error:" + ex.Message)
End Try
End Function
我需要調用函數Get_RS_Connection()在不同的類,而不是所有得到的連接再次的方式和硬編碼....我想打電話給在SQL連接聲明上面的類
Namespace FS_Library
Public Class FS_Errorlog
Inherits FS_BaseClass
Try
**cn = New SqlConnection("Data Source=***********;UserID=sa;Password=*****;database=*********")**
cmd = New SqlCommand("dbo.FS_ErrorLog_ADD", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandTimeout = Convert.ToInt32(ConfigurationSettings.AppSettings("Command_Timeout"))
Me.AddParameter(cmd, "@p_tableKey", SqlDbType.Int, tableKey)
Me.AddParameter(cmd, "@p_FunctionCode", SqlDbType.Int, FunctionCode)
Me.AddParameter(cmd, "@p_TableAlias", SqlDbType.VarChar, TableAlias)
Me.AddParameter(cmd, "@p_ValidationCode", SqlDbType.Int, ValidationCode)
If Filename = "" Then
Filename = "N/A"
End If
Me.AddParameter(cmd, "@p_FileName", SqlDbType.VarChar, Filename)
Me.AddParameter(cmd, "@p_Message", SqlDbType.VarChar, Message)
Me.AddParameter(cmd, "@p_CreateUser", SqlDbType.VarChar, userID)
Me.AddParameter(cmd, "@p_UserActionID", SqlDbType.UniqueIdentifier, UserActionID)
cn.Open()