注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

樱之花

叶散的时候,你明白欢聚;花谢的时候,你明白青春.

 
 
 

日志

 
 
关于我

分类中“我的实验室”是我在日常工作中的一些知识总结,有些写的比较匆忙,可能大家在阅读时会产生困扰,后期有时间我会重新整理编辑,谢谢大家的到访,您们的支持是我前进的动力!

网易考拉推荐

ASP FAQ,无法打开关键字的解决方案   

2007-05-17 09:34:29|  分类: ASP开发 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Troubleshooting ASP and Microsoft Access Databases

There can be a number of problems that you find when you are dealing with Microsoft Access Databases from ASP and this article tries to show you some of them and the methods to get around the problem. This article will focus on using Microsoft ADO (ActiveX Data Objects) as the method to communicate with the databases.

Problem #1 - Creating an ADO connection string

Depending on the database you are connecting to you need to use different ADO connection strings. These are quite simply to create by hand but I find it much better to use a utility that I wrote to generate the ADO connection strings using a wizard.

This utility including full source code in Delphi is available at http://www.iisfaq.com/Articles/307/ .

ASP FAQ,无法打开关键字的解决方案  - 魔术师 - 樱之花 yinzhihua2008

Even with the utility above we need to determine the correct driver to use to connect to the database.

Microsoft Access 97 Microsoft Jet 3.51 OLE DB Provider
Microsoft Access 2000  Microsoft Jet 4.0 OLE DB Provider
Microsoft Access XP Microsoft Jet 4.0 OLE DB Provider

Note: The latest versions of Microsoft MDAC which includes Microsoft ADO does not include the Microsoft Jet 3.51 OLE DB Provider.

To download the latest version of Microsoft MDAC please go to http://www.microsoft.com/data/download.htm ; you can also download the latest version of the Jet Components from the same location.

Example Connection String

Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source=c:\testing\TestForWebServer.mdb;Persist Security Info=True

The example connection string above first specifies the driver that we are going to use. The database is an Access 2000 database so we are using the Microsoft.Jet.OLEDB.4.0 provider.

In the example above we have a blank password as shown by the Password="" in the connection string. We need to be awear that the above connection string is not valid in ASP as it stands now.

Using this connection string from an ASP page will result in an error because of the Password=""

Result of above command

ADODB.Connection (0x800A0BB9)

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

/users.asp, line 15

The reason that the above code fails is because if you look closely at the provider string what the ASP engine actually parses is not what you think it is.

The provider string above is actually rendered to :

Provider=Microsoft.Jet.OLEDB.4.0;Password=";Data Source=c:\testing\TestForWebServer.mdb;Persist Security Info=True

If you look closely at the Password= portion of the provider string we see only 1 dbl-quote (") and not the two sets of dbl-quotes the provider string originally contained. This is because the dbl-quote (") is a string delimiter in VB Script. We must escape the quote; this means we need to replace the single dbl-quote (") with a two dbl-quotes ("").

This change to our ASP code is shown below.

Result of above command

Nothing is returned because there is no errors our any output from the above command. If you get an error the web server may not have

the right to open the database. See the next section for help on this problem.

 

Problem #2 - NTFS Permissions

NTFS permissions play a big role in Microsoft Access Databases and ASP. The reason for this is the fact that the web server runs under a specific user account; this user account is by default the IUSR_XXXX where XXXX is the name of the computer the web server is running on. If the computer name is CCROWE then the web server account by default will be IUSR_CCROWE.

If the web server is configured to run out-of-process which means its Application Protection is set to High (Isolated) on the Home Directory tab of the web server properties then it runs as a different user account. The out-of-process user account is called IWAM_XXXX where XXXX is the name of the computer the web server is running on. So again if we use the computer name of CCROWE the out of process user account is called IWAM_CCROWE.

Note: It is very important to remember the IUSR_ and the IWAM_ accounts when dealing with access permissions.

In our sample below the database is stored at c:\testing\ttestforwebserver.mdb

You may see the following error if you just create a database and try to access it through ASP.

Result of above command

Microsoft JET Database Engine (0x80004005)

The Microsoft Jet database engine cannot open the file 'C:\testing\TestForWebServer.mdb'. It is already opened exclusively by another user, or

you need permission to view its data.

/users.asp, line 13

This error message is quite good at explaining the problem; but there are other permission based error messages that can be returned that are very hard to decipher if you have never seen it before.

Result of above command

Microsoft OLE DB Provider for ODBC Drivers (0x80004005)

[Microsoft][ODBC Microsoft Access Driver] General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x614 Thread 0x6c0 DBC 0x21dd07c Jet'.

(FileName), (LineNumber)

The above two error messages relate to the fact that the web server account does not have the rights to access the database.

Setting the following NTFS permissions will cure the errors above.

Task   Permission   User Accounts
Actual MDB Database File (*.MDB)   Modify   IUSR_CCROWE, IWAM_CCROWE 

Folder where the *.MDB file is located   Modify   IUSR_CCROWE, IWAM_CCROWE 

Temp Directories   Modify   IUSR_CCROWE, IWAM_CCROWE 

Notes:

  • If you set the FOLDER permission first and then create your database the database will by default inherit the permissions from the folder.
  • The Modify NTFS permission in Windows 2000 is Change under Windows NT 4.
  • Change the IUSR_CCROWE used above to the user account that the web server is using
  • I have also found that the JET Engine creates temporary files as well, these normally get stored in the Temp directory (you can find the temp directory by going into Control Panel -> System -> Advanced - Environment Variables, I would set both the TMP and TEMP folders to allow Change Permissions for the IUSR account.

Other References that may be helpful in your database problems.

  评论这张
 
阅读(505)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017