从app.config文件中提取连接字符串 [英] Extract connection string from app.config file
本文介绍了从app.config文件中提取连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用
昏暗的ConStr = configurationmanager.connectionstring("zxcv").tostring
但这不起作用
我正在使用.net framework 3.0 vs 2008
I am using
dim ConStr= configurationmanager.connectionstring("zxcv").tostring
but this is not working
i am using .net framework 3.0 vs 2008
推荐答案
尝试一下:
Try this:
Private Shared Function GetConnectionStringByName( _
ByVal name As String) As String
'' Assume failure
Dim returnValue As String = Nothing
'' Look for the name in the connectionStrings section.
Dim settings As ConnectionStringSettings = _
ConfigurationManager.ConnectionStrings(name)
'' If found, return the connection string.
If Not settings Is Nothing Then
returnValue = settings.ConnectionString
End If
Return returnValue
End Function
它直接来自MSDN:存储和检索连接字符串 [ ^ ]
可能值得您下次尝试使用Google ...
It is taken directly from MSDN:Storing and Retrieving Connection Strings[^]
It might be worth your trying Google first, next time...
这篇关于从app.config文件中提取连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文