-1
请参阅下面的代码:重用连接字符串
Namespace DataAccessGateway
Public Class clsAudit
Implements IAudit
Private _ConString As String
Private _Provider As String
Public Sub New()
_ConString = ConfigurationManager.ConnectionStrings("dbConnection").ConnectionString
_Provider = ConfigurationManager.ConnectionStrings("dbConnection").ProviderName
End Sub
Public Function AddAudit(ByVal tyDeletion As typeDeletion) As Integer Implements IAudit.AddAudit
Dim intCount As Integer
Dim objParameterValues As New clsParameterValues
Dim iConnectionBLL As iConnectionBLL
Dim tyInnkeeperPremises As New typeInnkeeperPremises
Dim objCon As DbConnection
Try
Dim paramValues() As DbParameter
objParameterValues = New clsParameterValues
iConnectionBLL = New clsConnectionBLL()
objCon = iConnectionBLL.getDatabaseTypeByDescription("AUDIT")
Using objCon
Dim strSQL As String
strSQL = "INSERT INTO dbAudit (Reference) VALUES (@Reference)"
objParameterValues.AssignParameterValues("@Reference", tyDeletion.Reference, 1)
paramValues = objParameterValues.getParameterValues
intCount = clsDatabaseHelper.ExecuteNonQuery(objCon, CommandType.Text, strSQL, paramValues)
End Using
Return intCount
Catch ex As Exception
Return -1
End Try
End Function
End Class
End Namespace
这段代码被称为批处理作业,即它可以在一天一下子被称为千万倍的一部分。审计数据库的连接字符串存储在加密的数据库表中,即tbl_database(getDatabaseTypeByDescription查询此表)。因此,必须查询数据库高达一千万次以获得相同的连接字符串一千万次。将连接字符串放入静态变量还是有更好的方法是不好的做法?
我知道将连接字符串放在配置文件中会更好,但我希望能够保持一致。
连接字符串通常存储在应用程序配置文件中。或者,它可以是注册表设置。我从来没有见过将它存储在数据库中的应用程序,因此您需要该数据库的连接字符串来获取所需的连接字符串。你有没有理由不直接做事? – Neolisk 2013-04-23 21:34:32
@Neilisk,谢谢。 Web应用程序查询数据库以获取许多连接字符串。当应用程序启动时,是否可以从配置文件中提取连接字符串并将其加载到app.config中? – w0051977 2013-04-23 21:50:25
'提取...字符串从...配置文件并加载...到... app.config ...'。配置文件和app.config是一回事,不是吗?请解释。请在你的问题中详细说明多个连接字符串。 – Neolisk 2013-04-23 21:52:31