请教各位高手,Delphi怎样连接Microsfot SQL Server 7.0数据库?具体的属性设置及代码应怎样写?(100分)

  • 主题发起人 主题发起人 震三山
  • 开始时间 开始时间

震三山

Unregistered / Unconfirmed
GUEST, unregistred user!
具体的属性设置及代码最好详细一点儿!
 
先用ODBC建立一个系统dsn
拖一个Adoquery到Form上
双击,选择ConnectionString
然后根据提示一步步走,最后test,OK!
 
function TryConnect(ADOConnection: TADOConnection;SVName,DBName,UserID,PassWD:String): Boolean;
begin
with ADOConnection do begin
Connected := False;
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
+UserID+';PWD='+PassWD+';Initial Catalog='+DBName+';Data Source='+SVName;
try
Connected := True;
except
if MessageBox(Application.Handle,'Error for Database Link!','Information',
MB_ICONWARNING+MB_RETRYCANCEL)<>IDRETRY then Break;
end;
Result := Connected;
end;
end;
 
function TryConnect(ADOConnection: TADOConnection;SVName,DBName,UserID,PassWD:String): Boolean;
begin
with ADOConnection do begin
Connected := False;
ConnectionString := 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID='
+UserID+';PWD='+PassWD+';Initial Catalog='+DBName+';Data Source='+SVName;
try
Connected := True;
except
if MessageBox(Application.Handle,'Error for Database Link!','Information',
MB_ICONWARNING+MB_RETRYCANCEL)<>IDRETRY then Break;
end;
Result := Connected;
end;
end;
这个函数就可以了啊!
 
这个链接可以在属性窗口中完成的,用adotable或adoquery控件,它们有一个
conenctionstring属性,在里面选择“use connection string”,然后点build按钮选
“Microsoft OLE DB Provider For SQL server”,然后的问题就SQL链接的问题了,看看
提示就知道了
 
ADO通过ODBC连接
 
上面都已经说了。
 
后退
顶部