在Linux下实现对Microsoft Access Database(.mdb)查询访问

在Linux下实现对Microsoft Access Database(.mdb)查询访问

You will need the following:
Linux ( I’m running RedHat 9.0)
PHP
Apache
UnixODBC
MDBTools

INSTRUCTIONS
1) Download the UnixODBC RPM, found here. I installed unixODBC version 2.2.5.1.
rpm -ivh unixODBC-2-2.5-1.i386.rpm

2) Download the MDBTools rpm, found here. I installed mdbtools version 0.5.1. Read limitations!
rpm -ivh mdvtools-0.5-1.i386.rpm

3) Download the MDBTools ODBC driver rpm. Again I installed version 0.5-1.i386.rpm. Read limitations!
rpm -ivh mdbtools-odbc-0.5-1.i386.rpm

4) Add the mdbtools driver to your unixODBC config.
Create a new text file. NON-LINUX user: Beware do not do this on windows as you might get werid new lines, use vi.

[MDBToolsODBC]
Description = MDB Tools ODBC drivers
Driver = /usr/lib/libmdbodbc.so.0
Setup =
FileUsage = 1
CPTimeout =
CPReuse =

NOTE: The driver may be in /usr/local/lib/libmdbodbc.so.0. This happens if you build from source and use the make install command. The RPM puts it in /usr/lib.
Now install the driver using the file you created. This is called a template file.
odbcinst -i -d -f template.file

5) Define the datasource name. This is done in the /etc/odbc.ini file. So pull up this file in vi or another text editor and add the following lines.

[Dogs]
Description = Microsoft Access Database of Dogs
Driver = MDBToolsODBC
Database = /var/data/my_dog_db.mdb
Servername = localhost
UserName =
Password =
port = 5432

That’s it you should now have an odbc connection available. I will demonstrate using php, this assumes that your php is compiled with UnixODBC support, the version that ships with Redhat 9 does if yours does not then you can learn how here.

So I will write a quick php script to query my dogs database and print out the names and weights of my dogs.

$myDB = odbc_connect(”Dogs”,”",”");
$query = “select name, weight from dog_list”;
$result = odbc_exec($myDB, $query);
while (odbc_fetch_row($result)) {
print “Name = ” . odbc_result($result,”name”);
print “
Weight = ” . odbc_result($result,”weight”);
}

If you get a php error that says odbc_connect is not a function then see if you have php-odbc installed. Do rpm -qa php-odbc. If you see php-odbc returned then you have it if not install it., the rpm is available on the redhat discs.

Limitations:
- As of the time of writing this entry MDBTools did not support write access to the mdb files. This was fine for my purposes as I was reading data in and sticking it into a mysql database.
- There is a bug in MDBTools v0.5 which does not allow you to query tables or columns with an underscore. This was a bug I hit early on, but it has been fixed in new version 0.6 but that has not been released as of the time of writing this article. So I recompiled the 0.5 source code with the fix from the 0.6 CVS repository. I have bundled it into a 0.5 release and have the two rpms mentioned above here:
mdbtools-0.5-1.i386.rpm
mdbtools-odbc-0.5-1.i386.rpm

I would check the official download site before using my hacked version as I’m sure this bug will be fixed in 0.6 (plus rumor has write access will be present as well).

from http://www.517sou.net/blogview.asp?logID=1069&cateID=12

常见错误 不能打开注册表关键字 'Temporary (volatile) Jet DSN 解决方法/asp+access

Microsoft   OLE   DB   Provider   for   ODBC   Drivers   (0x80004005)
[Microsoft][ODBC   Microsoft   Access   Driver]常见错误   不能打开注册表关键字   'Temporary   (volatile)   Jet   DSN   for   process   0xbec   Thread   0xd34   DBC   0x3510024   Jet '。

首先检查程序里数据库路径没有写错
然后检查机器的C:WINDOWStemp有没有给IIS帐户“写入”权限
还要检查数据库所在目录是否有可读可写权限
然后尝试注册组件试一试
还有考虑把MSDTC组件卸载了重新安装一次

1、停止MSDTC服务:net stop msdtc
2、卸载MSDTC服务:msdtc -uninstall
3、重新安装MSDTC服务:msdtc -install
4、确认在事件查看器中msdtc服务已经正常启动[这步很关键,如果没有,重新启动下电脑看看]

如果正常的话请你跳过此步骤;如果出错,无法正常启动,请在开始菜单的运行中 运行:msdtc -resetlog 以创建日志文件。重起机器,检查IIS是否可以正常使用,若不行继续。

asp+access很不爽,IIS用户需要对系统临时文件夹的读写权限,让人感觉不安全有隐患。应该是access数据库运行的临时文件要放到windows临时目录里,但这个临时文件又不能设置到其它文件夹,而且access的数据库操作又不能在一个隔离的用户下进行(它直接使用IIS用户),所以,如果可以就放弃asp+access吧,甚至连asp都放弃

变态的Access2007:在Access2007中创建SQL传递查询(执行SQl语句)

1. 在“创建”选项卡中,单击“其他”组中的“查询设计”。
2. 单击“显示表”对话框中的“关闭”,而不添加任何表或查询。
3. 在“设计”选项卡中,单击“查询类型”工作组中的“传递”。
4. 单击“显示/隐藏”工作组中的“属性表”以显示查询的属性表。
5. 在查询的属性表中,将鼠标指针置于“ODBC 连接字符串”属性中,然后单击“生成”(...) 按钮。
利用“ODBC 连接字符串”属性,可以指定与要连接的数据库有关的信息。可以键入连接信息,或者单击“生成”,然后输入与要连接的服务器有关的信息。
6. 当提示您是否在连接字符串中保存密码时,如果希望将密码和登录名存储在连接字符串信息中,请单击“是”。
7. 如果查询不属于可返回记录的类型,请将“ReturnsRecords”属性设置为“No”。
8. 在“SQL 传递查询”窗口中,键入您的传递查询。例如,下面的传递查询在 Select 语句中使用 Microsoft SQL Server TOP 运算符,以仅返回示例数据库的“订单”表中的前 25 份订单:
Select TOP 25 orderid from orders
9. 若要运行查询,请单击“设计”选项卡的“结果”组中的“运行”。对于返回记录的 SQL 传递查询,请单击状态栏上的“数据表视图”。
10. 如果需要,Microsoft Access 将提示您输入有关服务器数据库的信息