sadier

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
http://www.communitymx.com/content/article.cfm?page=4&cid=A6D0B2B03FC484DB

Using a Password Protected Access Database

When your Access database has a password on it, you have to change the way you compose your connection string:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\somepath\mydatabase.mdb;Jet
OLEDB:Database Password=pass;

You may have to specify the system OLEDB database file in the string as well. This one should work in Windows 2000:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\somepath\mydatabase.mdb;Persist Security Info=False;Jet OLEDB:System database=C:\Program Files\Common Files\System\System.mdw;Jet OLEDB:Database Password=pass;

And this one should work in Windows NT 4:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\somepath\mydatabase.mdb;Persist Security Info=False;Jet OLEDB:System database=C:\winnt\system32\System.mdw;Jet OLEDB:Database Password=pass;

For more information on creating OLE DB connection strings, check out the MS technote at http://support.microsoft.com/support/kb/articles/Q264/6/91.ASP

Using Server.Mappath in Dreamweaver

Beginning with UltraDev 4, the use of Server.Mappath is allowed in connection strings. The requirements are as follows:

  • You have to specify "Application Server" when defining the connection. Local connections aren't supported.
  • You have to specify the path to the root of the Web server or virtual directory in your connection string.
  • Make sure you put quotes around the first part of your connection string.

A typical DSNLess connection to an Access database using Server.Mappath in VBScript looks like this. Please note that this is ONE LINE of text in your Custom Connection string dialog box:

"Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Server.Mappath("\somepath\dbname.mdb") & ";Uid=Admin;Pwd=pass;"

A typical OLEDB connection string for MS Access is as follows:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("\somepath\dbname.mdb") & ";User Id=admin;Password=pass;"

Note that if you are using ASP JScript, you should change the & signs to + signs, like this:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.Mappath("\somepath\dbname.mdb") + ";User Id=admin;Password=pass;"

The format of the string is the same as the strings that were listed previously that used database locations. When using Server.Mappath, the Server.Mappath statement is concatenated to the string, and actually takes the place of the physical location of the database in the string, like this:

OLE DB Connections:

MS Access OLE DB connection

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\somepath\dbname.mdb;User Id=admin;Password=pass;

Oracle OLE DB connection

Provider=OraOLEDB.Oracle;Data Source=dbname;User Id=admin;Password=pass;

MS SQL Server OLE DB connection

Provider=SQLOLEDB;Data Source=machineName;Initial Catalog=dbname;User ID=sa;Password=pass;

MS SQL Server OLE DB connection using an IP address

Provider=SQLOLEDB; Data Source=xx.xx.xx.xx,1433; Network Library=DBMSSOCN; Initial Catalog=dbname;User ID=sa;Password=pass;

MS Text Driver OLE DB connection

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\yourpath;Extended Properties='text;FMT=Delimited'"

It's important to use the quotes with this driver in the Custom Connection dialog box

If you don't know the drive path to the database after uploading, you can download a server behavior from http://www.basic-ultradev.com/extensions/getdatabasepath.mxp and put it on a blank page and fill in your database name. Upload it to the server and browse the page. The connection string for DSNless connection will be in the browser window and you can cut and paste into Dreamweaver.

Alternatively, you can simply place some ASP code into your HTML code window:

<%=Server.MapPath("/")%>

This will give you the root folder for your website on the server. Then you can use the information to create a path string for your database to use in the ADO Connection String. It's much better to find out your path ahead of time than to use the Server.Mappath method. Server.Mappath has to create the path to the database each time your page is viewed. It's the same principle as looking up something in the index of a book. If you know the page number, it's quicker to go directly to the page rather than looking it up each time.

posted on 2006-01-02 23:25  毛小华  阅读(406)  评论(0编辑  收藏  举报