uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Registry, Des, DB, ADODB, RzTabs, AdvGlowButton, DBGridEhGrouping, GridsEh, DBGridEh, RzPanel,DBGridEhImpExp, ExtDlgs, Mask, RzEdit, RzButton, Diskid; //-------------------------------打开界面判断是否连接------------ procedure TFRMMAIN.FormShow(Sender: TObject); var MyReg : TRegistry; constr, FWQMC, SJKMC, YHMC, YHMM: string; begin EDTSERVER.Enabled:=false;//服务器名称 EDTDATA.Enabled:=false;//数据库名称 EDTUSER.Enabled:=false;//sql用户 EDTPSW.Enabled:=false;//密码 MyReg:=TRegistry.Create; MyReg.RootKey:=HKEY_LOCAL_MACHINE; if MyReg.OpenKey('\SOFTWARE\SW\SWDB', false) then begin if MyReg.ValueExists('connectstr') then begin constr:=MyReg.ReadString('ConnectStr'); FWQMC:=MyReg.ReadString('Server'); SJKMC:=MyReg.ReadString('DataBase'); YHMC:=MyReg.ReadString('User'); YHMM:=MyReg.ReadString('PassWord'); EDTSERVER.Text:=DecryStrHex(FWQMC,'※★'); EDTDATA.text:=DECRYSTRHEX(SJKMC,'※★'); EDTUSER.text:=DECRYSTRHEX(YHMC,'※★'); EDTPSW.text:=DECRYSTRHEX(YHMM,'※★'); end; end; AConnt.Close; constr := 'Provider=SQLOLEDB;Password=' + trim(EDTPSW.Text) + ';Persist Security Info=True;User ID=' + trim(EDTUSER.Text) + ';Initial Catalog=' + trim(EDTDATA.Text) + ';Data Source=' + trim(EDTSERVER.Text); AConnt.ConnectionString := constr; try AConnt.Open; //Application.MessageBox('数据库连接成功!', '提示', 0); except Application.MessageBox('数据库连接失败!', '提示', mb_iconerror + mb_ok); end; AConnt.Close; end; //-------------------------------测试数据库连接-------------------- procedure TFRMMAIN.BTNTESTClick(Sender: TObject); var ss,s1,s2,s3,s4: string; begin s1:=Trim(EDTSERVER.text); s2:=Trim(EDTDATA.text); s3:=Trim(EDTUSER.text); s4:=Trim(EDTPSW.text); ss := 'Provider=SQLOLEDB;Password=' + s4 + ';Persist Security Info=True;User ID=' + s3 + ';Initial Catalog=' + s2 + ';Data Source=' + s1; try AConnt.Close; AConnt.ConnectionString := ss; AConnt.Open; Application.MessageBox('数据库连接成功!', '提示', 0); except Application.MessageBox('数据库连接失败,请重新配置!', '提示', mb_iconerror + mb_ok); exit; end; end; //-----------------------------修改数据库配置------------------------------------------ procedure TFRMMAIN.BTNBCClick(Sender: TObject); var MyReg: TRegistry; sw,ssbl,ssba,sshs,FWQMC,SJKMC,YHMC,YHMM: string; begin sw := 'Provider=SQLOLEDB;Password=' + trim(EDTPSW.Text) + ';Persist Security Info=True;User ID=' + trim(EDTUSER.Text) + ';Initial Catalog=' + trim(EDTDATA.Text) + ';Data Source=' + trim(EDTSERVER.Text); sw := EncryStrHex(sw, '※★'); FWQMC := EncryStrHex(TRIM(EDTSERVER.Text), '※★'); SJKMC := EncryStrHex(TRIM(EDTDATA.Text), '※★'); YHMC := EncryStrHex(TRIM(EDTUSER.Text), '※★'); YHMM := EncryStrHex(TRIM(EDTPSW.Text), '※★'); MyReg := TRegistry.Create; MyReg.RootKey := HKEY_LOCAL_MACHINE; if MyReg.OpenKey('\SOFTWARE\SW\SWDB', true) then begin MyReg.WriteString('ConnectStr', sw); MyReg.WriteString('SERVER', FWQMC); MyReg.WriteString('DATABASE', SJKMC); MyReg.WriteString('USER', YHMC); MyReg.WriteString('PASSWORD', YHMM); end; MyReg.Free; Application.MessageBox('数据库设置已保存!-', '提示', 0); EDTSERVER.Enabled:=false; EDTDATA.Enabled:=false; EDTUSER.Enabled:=false; EDTPSW.Enabled:=false; end; //-------------------------保存配置好的数据库信息--------------------- procedure TFRMMAIN.BTNBCClick(Sender: TObject); var MyReg: TRegistry; sw,ssbl,ssba,sshs,FWQMC,SJKMC,YHMC,YHMM: string; begin sw := 'Provider=SQLOLEDB;Password=' + trim(EDTPSW.Text) + ';Persist Security Info=True;User ID=' + trim(EDTUSER.Text) + ';Initial Catalog=' + trim(EDTDATA.Text) + ';Data Source=' + trim(EDTSERVER.Text); sw := EncryStrHex(sw, '※★'); FWQMC := EncryStrHex(TRIM(EDTSERVER.Text), '※★'); SJKMC := EncryStrHex(TRIM(EDTDATA.Text), '※★'); YHMC := EncryStrHex(TRIM(EDTUSER.Text), '※★'); YHMM := EncryStrHex(TRIM(EDTPSW.Text), '※★'); MyReg := TRegistry.Create; MyReg.RootKey := HKEY_LOCAL_MACHINE; if MyReg.OpenKey('\SOFTWARE\SW\SWDB', true) then begin MyReg.WriteString('ConnectStr', sw); MyReg.WriteString('SERVER', FWQMC); MyReg.WriteString('DATABASE', SJKMC); MyReg.WriteString('USER', YHMC); MyReg.WriteString('PASSWORD', YHMM); end; MyReg.Free; Application.MessageBox('数据库设置已保存!-', '提示', 0); EDTSERVER.Enabled:=false; EDTDATA.Enabled:=false; EDTUSER.Enabled:=false; EDTPSW.Enabled:=false; end;
connection
原创mrstarwei ©著作权
文章标签 connection 配置连接 文章分类 数据库
上一篇:配置连接
-
PowerDesigner用Connection profile导出Mysql数据字典常见问题
PowerDesigner 导出数据字典时,连接数据库会提示错误,本文针对自己遇到的问题,总结处理方法。
java mysql PowerDesigner -
WIFI - Connection
WIFI Regulatory Domain
Domain Image