使用我的ADODB.Connection打开webconfigs appSettings键?

时间:2013-12-20 14:53:45

标签: vb.net asp-classic web-config connection adodb

*所以我坚持这个。使用VB,经典ASP。我想使用代码标记1.)破解代码,因为我希望dbs_connection来自我的网站main web.config,目前网站硬编码.asp文件来获取连接,请参阅2.)此代码工作,所以例如,当我们有一个数据库移动时,这会被查看并破坏。*

1。)代码破碎。

'.Asp file
dim dbs_connection = ConfigurationSettings.AppSettings("ConnectString_dbs")
dim objRecordSet,DatabaseQueryString
set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.open dbs_connection

'root web.config note:this works have many other keys in here<br/> 
<appSettings>
<add key="dbs_connection" value="Provider=sqloledb;Network Library=DBMSSOCN;Data Source=VDB022;Initial Catalog=dbs;User ID=average; Password=@v3r@@3;OLE DB Services = -1;"/><br/>
<appSettings>

错误

Microsoft VBScript compilation error '800a0401' 

Expected end of statement 

/Sites/includes/DisplayDocAdminRepLinks.asp, line 35 

dim dbs_connection = ConfigurationSettings.AppSettings("ConnectString_dbs")

2.。)此代码有效

const dbs_connection = "Provider=sqloledb;Network Library=DBMSSOCN;Data Source=DB022;Initial Catalog=dbs;User ID=average; Password=@v3r@@3;OLE DB Services = -1;"

dim objRecordSet,DatabaseQueryString
set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.open dbs_connection

1 个答案:

答案 0 :(得分:-1)

您没有通过经典asp访问web.config。 web.config ist ASP.net

通常使用global.asa来存储经典asp

中的连接字符串

示例global.asa:

<script language="VBScript" runat="Server">
sub session_OnStart
    session("dbs_connection") = "Provider=sqloledb;Network Library=DBMSSOCN;Data Source=DB022;Initial Catalog=dbs;User ID=average; Password=@v3r@@3;OLE DB Services = -1;"

end Sub
</script>

示例asp文件:

dim objRecordSet, DatabaseQueryString
set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.open session("dbs_connection")