0

我有一个asp文件,其中包含connectionString我的数据库。

我想知道是否有办法在用户尝试登录系统之前更改该信息。

我命名它_conn.asp,它包含以下 asp 代码

dim conn

sub OpenConn()
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open = "Driver=driver_name; SERVER=server_name; uid=user_name; pwd=user_pwd; DATABASE=db_name;"
End sub

Sub CloseConn()
    Conn.Close
    Set Conn = Nothing
End sub

我希望能够更改该asp 文件中的 、 、driverserver信息。uidpwddatabase

首先,我意识到 xml 文件将是最好的选择,但后来我听说了一堆涉及将 connectionString 放在 xml 文件上的安全问题。

如果无法更新文件,那么在经典 ASP_conn.asp中制作可更新文件以保存到数据库的最佳做法是什么?connectionString

4

1 回答 1

0

Usually you would put the connection string into a separate file in the directory not listed in IIS. Say, your ASP pages in Website\Scripts folder. Create a new folder Website\Includes. make sure it is not listed. Create a file, say DSN.inc inside this folder.

Now, in your asp pages add this line:

<!-- #include FILE="../Includes/dsn.inc" -->

DSN.inc would contain the connection string (here is an example of Jet4.0 connection string)

  set rs=Server.CreateObject("adodb.Recordset")
  sDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("..\Databases\db.mdb") & "; "

In your ASP pages just re-use rs

于 2013-05-10T02:42:03.607 回答