mysql表打包到程序中_关于数据库程序的打包

本文介绍了如何在Delphi应用中利用ADO连接MySQL数据库,避免依赖DSN,通过设置ConnectionString直接访问数据库文件。作者分享了从手动设置DSN到动态配置的探索过程,并提供了测试成功的代码示例,简化了数据库程序的打包和部署。
摘要由CSDN通过智能技术生成

利用开发工具delphi设计一个数据库应用程序,利用ado(ActiveX Data Objects)进行设计的方案适合基于在本机上运行或利用SQL进行访问的C/S结构的应用方案。总之应用还是比较好,我用delphi+access进行了一个程序的设计和开发,已经完成了基本的功能,但是在程序打包时遇到一些棘手的问题(用了WISE),打包应该没问题比较简单,主要是给要安装软件的电脑进行安装,很多这样那样的问题就出现了,可能很多新手都困扰过,当要安装软件的那台电脑没有安装ODBC驱动时怎么把驱动一起打包分发?如果有ODBC驱动,但没有安装OFFICE办公软件怎么处理?如果软件需要导出成Excel表格时,怎么进行信息的处理?

带着好多疑惑,查了两天的网,也没有大致的头绪,快把第一次见到自己的安装程序运行时的激动心情弄得一团糟!

下面记录一下个人的学习过程和理解:

1、需手动设DSN或在delphi程序中动态设DSN的过程略过;

2、查MSDN关于ado访问access,说明了为什么不用设置DSN,主要是应用于asp、Visual Fox等下面是MSDN的部分文档,也许说明了adoconnection的连接字符串的作用:

My first exposure to ADO was helping my wife with her pet Web site on an IIS where she was developing a pedigree database for Welsh Corgis (http://corgi.folkarts.com/pedigree/). First, I discovered that the administrators did not have to create a DSN for her Microsoft Access database; instead, I opened it with the following code:

Set DogConn=CreateObject("ADODB.Connection")

DogConn.Open "Driver=Microsoft Access Driver (*msb);DBQ=C:\Corgi\DogTree.Mdb"

If she wanted to use another file-based database system like Microsoft Visual FoxPro®, it is just as simple. If I wished to fine-tune the connection, it is trivial:

DogConn.Open = "DRIVER={Microsoft Access Driver (*.mdb)};User Id=admin; DBQ=C:\Corgi\DogTree.Mdb; DefaultDir=C:\Corgi;

FIL=MS Access; ImplicitCommitSync=Yes; MaxBufferSize=512; MaxScanRows=8; PageTimeout=5; SafeTransactions=0;

Threads=3; UserCommitSync=Yes;"

What impressed me was the speed of ADO—she could display the known pedigree of our dogs back 12 generations ( a 211branch tree!) in seconds using an Access database as the source. (Try her Web page yourself!)

When I started developing industrial-grade Web applications going against Windows NT and SQL Server, I found that the use of system DSNs often leads to days tracking down setup errors on test boxes. The most common error was getting "GetOverLappedResult()" when accessing Windows NT and SQL Server from an IIS server. The cause was the DSN being set up (or later changed) to use Named Pipes to connect to Windows NT and SQL Server and not TCP/IP. The solution was to use the following string to set up the connection with the appropriate network connection:

Set MyConn=CreateObject("ADODB.Connection")

MyConn.Open " driver={SQL Server}; server=corwyn; database=family; UID=Woof; PWD=Bone; network=dbmsscon"

The `network=dbmsscon" parameters determines the network library to use, in this case TCP/IP.

对于数据库开发,除了利用别人的代码,或修改别人的代码达到一样的功效外,有空余时间还是应该对MSDN上讲解ado相关的重要内容进行一番查阅。

3、根据上面的用法,再看看下面delphi中用法,多少得些端倪吧:

ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Database Password=Admin;Data Source='+ExtractFileDir(application.Exename)+'\temp.mdb;user id=admin;Persist Security Info=False';

adoconnection1.Connected:=true;

快测试一下去。(有取程序路径用extractfilepath(application.ExeName),应该也是一样的道理)。在adoquery控件取adoconnction之前要设置好connectionString!

4、经过测试,过了!以后也用不着写DSN或设置数据源了。真是令人振奋!现在看起来,我做的程序才有点软件的感觉,这种过程和结果确实会让人兴奋。我这几年的学习还是没白费,可以拿出来见人了,高兴啊。还差把说明文档做好就可以打包发布了。软件版本V1.0,哈哈,yes!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值