自己写一个连接字符串就行了啊.adoconnection1.connectionstring:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=neverseen;Initial Catalog=test;Data Source=LIU'datasource=sqlserver实例; initial catalog=数据库; user id=用户名; password=密码;要是想列举sql server 服务器和列举数据库名称,搜索一下,讨论很多了.
function ConnMss(Conn: TADOConnection; ServerName, DBName, Logid, PassWord: string; var sErr: string): boolean; var str:string; begin //判断连接控件是否存在 if not Assigned(Conn) then begin result:=false; sErr:='所需 TADOConnection 控件不存在'; exit; end;
adoconnection1.connectionstring:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Password=neverseen;Initial Catalog=test;Data Source=LIU' adoconnection1.connected:=true; adoconnection1.LoginPrompt:=false; adoconnection1.Connected:=true; adoquery.Connection:=adoconnection1;begin adotable1.Locate('user',edit1.Text,[]); if adotable1.bof then showmessage('用户不存在') else begin if edit2.Text=adotable1.FieldValues['password'] then begin showmessage('successed'); form2.show; form1.Hide; end else showmessage('密码错误');
initial catalog=数据库;
user id=用户名;
password=密码;要是想列举sql server 服务器和列举数据库名称,搜索一下,讨论很多了.
PassWord: string; var sErr: string): boolean;
var
str:string;
begin
//判断连接控件是否存在
if not Assigned(Conn) then
begin
result:=false;
sErr:='所需 TADOConnection 控件不存在';
exit;
end;
//连接数据库
str:='Provider=SQLOLEDB.1;'+
'User ID='+Logid+';'+
'Password='+Password+';'+
'Initial Catalog='+DBName+';'+
'Data Source='+ServerName;
try
Conn.Close;
Conn.LoginPrompt:=false;
Conn.ConnectionString:=str;
Conn.Open;
except
result:=false;
showmessage('初始连接数据库出错!');
exit;
end;
result:=true;
end;
*****************************连接服务器*****************************
Data.ADOConnection1.Connected := False;
Data.ADOConnection1.ConnectionString := 'Provider=SQLOLEDB.1;' +
'Password=' + Trim(PasswordEdit.Text) +
';' +
'Persist Security Info=False;' +
'User ID=' + Trim(Edit1.Text) + ';' +
'Initial Catalog=RS;' +//RS 是数据库
'Data Source=' + Trim(Edit2.Text) + ';' ;
Data.ADOConnection1.Connected := True;
showmessage('服务器已经配置完毕,可以使用!')
*************************************用户登录验证****************
try
Data.adoLogin.Filter := 'name=' + char(39) + Edit1.Text + char(39);
Data.adoLogin.Filtered := True;
Data.adoLogin.Open;
except
showmessage('数据库连接错误,请与系统管理员联系!')
exit;
end;
if Data.adoLogin.RecordCount = 1 then
begin
if trim(Data.adoLogin.FieldByName('PASSWORD').AsString) =
trim(Edit2.Text) then
showmessage('密码确认,欢迎使用!')
else
showmessage('密码不匹配!请确认密码,并注意大小写');
end
else
showmessage('请确认用户名有误,是否正确');
end;
adoconnection1.connected:=true;
adoconnection1.LoginPrompt:=false;
adoconnection1.Connected:=true;
adoquery.Connection:=adoconnection1;begin
adotable1.Locate('user',edit1.Text,[]);
if adotable1.bof then
showmessage('用户不存在')
else
begin
if edit2.Text=adotable1.FieldValues['password'] then
begin
showmessage('successed');
form2.show;
form1.Hide;
end
else
showmessage('密码错误');