怎么知道用ODBC连接的数据库系统和名称和版本? 因用户使用的数据库系统不同,程序可能使用Interbase\sql server\Oracle系统之一。程序中用ODBC数据源来连接数据库,怎么得到当前连接的数据库系统的名称和版本呢?读注册表的ODBC信息吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先把 HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\数据源名\ 下的Driver项读出来,再用 GetFileVersionInfo获取Driver的名称和版本等信息。 这是我连接数据库的代码:var SQLFile, LogFile: TextFile; Error, SQLErr: Boolean; SQLFileName, strTmp: String; ComConnection: OleVariant;begin //设置日期格式 DateSeparator := '/'; TimeSeparator := ':'; LongTimeFormat := 'yyyy-mm-dd'; LongDateFormat := 'hh:nn:ss'; //打开连接 Error := False; ComConnection := CreateOleObject('ADODB.Connection'); ComConnection.ConnectionString := 'DSN=Ant2000;UID=Ant;PWD=tct1810';{ ComConnection.Mode := 3; // adModeReadWrite ComConnection.CursorLocation := 3; // adUseClient}{ 连接字符串 SQL Server 7 Provider=MSDASQL.1;Password=tct1810;Persist Security Info=True; User ID=ant2000p;Data Source=Ant2000View Interbase Provider=MSDASQL.1;Password=tct1810;Persist Security Info=True; User ID=ant;Data Source=Ant2000View;Connect Timeout=15; Extended Properties="DSN=Ant2000View;UID=ANT;PWD=tct1810; DB=E:\Work\Ant2000View\gdb\Ant2000.gdb";Locale Identifier=2052}// if ADOConnMain.Connected then Exit; try ComConnection.Open; except Error := True; end; while Error do if Application.MessageBox('错误:无法连接到数据库服务器' + #13#10'详细情况:数据库服务器没有启动或ODBC数据源没有设置或设置错误', PCHAR(Application.Title), MB_RETRYCANCEL or MB_ICONERROR)=IDRETRY then try ComConnection.ConnectionString := PromptDataSource(0, 'Provider=MSDASQL.1;Password=tct1810;' + 'Persist Security Info=True;Data Source=Ant2000;'); ComConnection.Open; Error := False; except Error := True; end else begin Tag := -1; Exit; end; ADOConnMain.ConnectionObject := IUnknown(ComConnection) as _Connection;除了读注册表,还有没有其他方法? 如何将2个ADOQuery连接不同数据库所得结果显示在一个DBGRID中? D7,ActiveX开发很奇怪的问题,求救阿 关于FTP文件上传问题,高手帮帮忙! 只剩40分,没法只能以后补了,急急急 关于解决滚动占用资源100%问题 菜鸟基础问题,散分~~~~~~~~~~~~~~ 怎样限定长度读取字符? 关于在GUITHREADINFO这个结构 求助:李维的<<Delphi5.X ADO/MTS专业程序设计篇>>在哪里有下载? dbrichedit到底怎么能显示一个记录集? Delhpi中如何调用Word、Excel呢? 我是delphi蔡鸟,弱智问题求解中,急
再用 GetFileVersionInfo获取Driver的名称和版本等信息。
var
SQLFile, LogFile: TextFile;
Error, SQLErr: Boolean;
SQLFileName, strTmp: String;
ComConnection: OleVariant;
begin
//设置日期格式
DateSeparator := '/';
TimeSeparator := ':';
LongTimeFormat := 'yyyy-mm-dd';
LongDateFormat := 'hh:nn:ss';
//打开连接
Error := False; ComConnection := CreateOleObject('ADODB.Connection');
ComConnection.ConnectionString := 'DSN=Ant2000;UID=Ant;PWD=tct1810';
{
ComConnection.Mode := 3; // adModeReadWrite
ComConnection.CursorLocation := 3; // adUseClient
}
{
连接字符串
SQL Server 7
Provider=MSDASQL.1;Password=tct1810;Persist Security Info=True;
User ID=ant2000p;Data Source=Ant2000View Interbase
Provider=MSDASQL.1;Password=tct1810;Persist Security Info=True;
User ID=ant;Data Source=Ant2000View;Connect Timeout=15;
Extended Properties="DSN=Ant2000View;UID=ANT;PWD=tct1810;
DB=E:\Work\Ant2000View\gdb\Ant2000.gdb";Locale Identifier=2052
}
// if ADOConnMain.Connected then Exit;
try
ComConnection.Open;
except
Error := True;
end; while Error do
if Application.MessageBox('错误:无法连接到数据库服务器'
+ #13#10'详细情况:数据库服务器没有启动或ODBC数据源没有设置或设置错误',
PCHAR(Application.Title), MB_RETRYCANCEL or MB_ICONERROR)=IDRETRY then
try
ComConnection.ConnectionString := PromptDataSource(0,
'Provider=MSDASQL.1;Password=tct1810;'
+ 'Persist Security Info=True;Data Source=Ant2000;');
ComConnection.Open;
Error := False;
except
Error := True;
end
else begin
Tag := -1;
Exit;
end; ADOConnMain.ConnectionObject := IUnknown(ComConnection) as _Connection;除了读注册表,还有没有其他方法?