ADO连接(简单问题,在线待) 怎么动态创建一个连接(服务器名:Server;用户名:Guest;密码:Pass)? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 function GetConnectionString: string;var SYSINI: TINIFile; ServerName, UserName, Password, tmpstr: string;begin SYSINI := TIniFile.Create(ExtractFilePath(Application.ExeName)+'DB.INI'); try ServerName := SYSINI.ReadString('Database', 'ServerName', ''); UserName := SYSINI.ReadString('Database', 'UserName', ''); tmpstr := SYSINI.ReadString('Database', 'Password', ''); Password := Decrypt(tmpstr, ''); Result := '';// Result := 'Provider=MSDAORA.1;Password=' + Password + ';Persist Security Info=True;User ID=' + UserName + ';Data Source='+ServerName+';Extended Properties=""'; Result := 'Provider=OraOLEDB.Oracle.1;Password=' + Password + ';Persist Security Info=True;User ID=' + UserName + ';Data Source='+ServerName+';Extended Properties=""'; finally SYSINI.Free; end;end;使用上面的函数:DataModule1.ADOConnection1.ConnectionString:= GetConnectionString;我用的是ORACLE的数据库 如果要把一个Connection对象连到另外一个上应该怎么写?例如:Conn2 和 Conn1 相等 ,好象写 Conn2 := Conn1 不对啊 procedure ReadFromIni(var aServerName, aDatabaseName, aUserName, aPassword: string);var IniFile: TIniFile; FileName: string;begin FileName := ExtractFilePath(application.ExeName) + '\DB.ini'; IniFile := TIniFile.Create(FileName); aServerName := IniFile.ReadString('DB', 'ServerName', ''); aDatabaseName := IniFile.ReadString('DB', 'DatabaseName', ''); aUserName := IniFile.ReadString('DB', 'UserName', ''); aPassword := IniFile.ReadString('DB', 'Password', ''); IniFile.Free;end;..//判断能否连接上数据库的函数function TfrmMain.DBConnect(aServerName, aDatabaseName, aUserName, aPassword: string): boolean;begin Result := True; Database.connected := False; Database.DriverName := 'SQL server'; //驱动名称 Database.Params.Values['Server Name'] := aServerName; //服务器名 Database.Params.Values['Database Name'] := aDatabaseName; //数据库名 Database.Params.Values['User Name'] := aUserName;//登录数据库用户名 Database.Params.Values['Password'] := aPassword; //相应数据库用户的密码 try Database.Connected := True; except result := False; end;end;....DB.ini内容如下[DB]ServerName=kingDatabaseName=wzglUserName=saPassword=...另一段代码//写入ini,并测试是否连接上procedure TfrmDBConnect.btnOKClick(Sender: TObject);begin writeToIni(edtServerName.Text, edtDatabaseName.Text, edtUserName.Text, edtPassword.Text); if frmMain.DBConnect(edtServerName.Text, edtDatabaseName.Text, edtUserName.Text, edtPassword.Text) then begin Application.MessageBox('连接成功', '提示', mb_iconInformation + mb_defbutton1); Connected := True; Close; end else begin Application.MessageBox('连接失败', '提示', mb_iconInformation + mb_defbutton1); end;end;刚才抄的! 如何判断listbox保存到文件成功了? delphi 从一个Excel导入另一个Excel 如何向导出的那个excel插入任意一列 QuickRep控件中的报表预览在win2000上出现的新问题 求无文档API库ws2help.dll相关资料 如何获取记录的最新时间? 我在一个form中有N个DBedit 我应该什么判断如果有一个dbedit的数据改变了,就执行某一段程序? 求使用modem和AT指令进行两台计算机通讯的例子 有关报表打印的问题 关于注册midas.dll的问题 简单的问题!送分哦 关于三层结构开发的步骤讨论 怎样在procedure中传值与传地址
var
SYSINI: TINIFile;
ServerName, UserName, Password, tmpstr: string;
begin
SYSINI := TIniFile.Create(ExtractFilePath(Application.ExeName)+'DB.INI');
try
ServerName := SYSINI.ReadString('Database', 'ServerName', '');
UserName := SYSINI.ReadString('Database', 'UserName', '');
tmpstr := SYSINI.ReadString('Database', 'Password', '');
Password := Decrypt(tmpstr, '');
Result := '';
// Result := 'Provider=MSDAORA.1;Password=' + Password + ';Persist Security Info=True;User ID=' + UserName + ';Data Source='+ServerName+';Extended Properties=""';
Result := 'Provider=OraOLEDB.Oracle.1;Password=' + Password + ';Persist Security Info=True;User ID=' + UserName + ';Data Source='+ServerName+';Extended Properties=""'; finally
SYSINI.Free;
end;
end;使用上面的函数:DataModule1.ADOConnection1.ConnectionString:= GetConnectionString;我用的是ORACLE的数据库
var
IniFile: TIniFile;
FileName: string;
begin
FileName := ExtractFilePath(application.ExeName) + '\DB.ini';
IniFile := TIniFile.Create(FileName);
aServerName := IniFile.ReadString('DB', 'ServerName', '');
aDatabaseName := IniFile.ReadString('DB', 'DatabaseName', '');
aUserName := IniFile.ReadString('DB', 'UserName', '');
aPassword := IniFile.ReadString('DB', 'Password', '');
IniFile.Free;
end;
..
//判断能否连接上数据库的函数
function TfrmMain.DBConnect(aServerName, aDatabaseName, aUserName, aPassword: string): boolean;
begin
Result := True;
Database.connected := False;
Database.DriverName := 'SQL server'; //驱动名称
Database.Params.Values['Server Name'] := aServerName; //服务器名
Database.Params.Values['Database Name'] := aDatabaseName; //数据库名
Database.Params.Values['User Name'] := aUserName;//登录数据库用户名
Database.Params.Values['Password'] := aPassword; //相应数据库用户的密码
try
Database.Connected := True;
except
result := False;
end;
end;
....
DB.ini内容如下
[DB]
ServerName=king
DatabaseName=wzgl
UserName=sa
Password=
...另一段代码
//写入ini,并测试是否连接上
procedure TfrmDBConnect.btnOKClick(Sender: TObject);
begin
writeToIni(edtServerName.Text, edtDatabaseName.Text, edtUserName.Text, edtPassword.Text);
if frmMain.DBConnect(edtServerName.Text, edtDatabaseName.Text, edtUserName.Text, edtPassword.Text) then
begin
Application.MessageBox('连接成功', '提示', mb_iconInformation + mb_defbutton1);
Connected := True;
Close;
end
else
begin
Application.MessageBox('连接失败', '提示', mb_iconInformation + mb_defbutton1);
end;
end;
刚才抄的!