请问如何在Console程序中使用TADOConnection对象,我的程序出现异常,请看代码!

风中飘扬的柳絮 2003-12-17 07:09:42

请各位高手指点....
---------------------------------
program Console;

{$APPTYPE CONSOLE}

uses
SysUtils,DB,ADODB;

var DBConn : TADOConnection ;
var DBConnStr : String;

begin
DBConnStr := 'Provider=SQLOLEDB.1;Data Source=localhost;User ID=sa;Password=sa;Persist Security Info=True;Initial Catalog=pubs';
DBConn := TADOConnection.Create(nil);
DBConn.ConnectionString := DBConnStr;
try
DBConn.Open;
except
on ex: Exception do
begin
WriteLn('Error');
end;
end

end.
...全文
57 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
thanks for your anwsers ,hch_45(んこん) gave me the correct way !
hch_45 2003-12-18
  • 打赏
  • 举报
回复
要uses ActiveX
hch_45 2003-12-18
  • 打赏
  • 举报
回复
begin
CoInitialize(nil);

DBConnStr := 'Provider=SQLOLEDB.1;Data Source=localhost;User ID=sa;Password=sa;Persist Security Info=True;Initial Catalog=pubs';
DBConn := TADOConnection.Create(nil);
DBConn.ConnectionString := DBConnStr;
try
DBConn.Open;
except
on ex: Exception do
begin
WriteLn('Error');
end;
end
CoUninitialize();
end.
noil0125 2003-12-18
  • 打赏
  • 举报
回复
uses
SysUtils,DB,ADODB,QForms;

...

begin
DBConn:=TADOConnection.Create(application);
...
end;
  • 打赏
  • 举报
回复
运行的时候出现一个异常:

Exception EOleSysError in module Console.exe at 000271FD.
CoInitialize 尚未被呼叫。.

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧