ADOConnection1.ConnectionString:=
' Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=mjb;Initial Catalog=dbStudentInfo;Data Source=MJB ';
end;上面User ID ,Data Source 会随着机器(就是放到别的机器上运行)的变化而变化,请问把它们设置为变量怎么做?怎么获得登陆服务器的用户名和数据源
' Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=mjb;Initial Catalog=dbStudentInfo;Data Source=MJB ';
end;上面User ID ,Data Source 会随着机器(就是放到别的机器上运行)的变化而变化,请问把它们设置为变量怎么做?怎么获得登陆服务器的用户名和数据源
解决方案 »
- Tedit控件不可通过键盘输入,但是可以接收刷卡器刷入
- 大虾帮忙看看ADO+Access的连接报错(Could not convert of type(Nnll) into type(string)
- 怎么用DLL完成一个客户端的功能
- 更改屏幕刷新率的问题
- 给大家试用一套开放的交易中间件MayGTS
- oracle中BLOB类型字段,,这个问题困扰好久了,在线!!
- 请教高手,DBGRID的使用,由某列录入值,从其它表返回值填充某些列值。急~马上给分
- 关于websnap中数据编辑的问题
- 老师要求做一个关于运筹学图书管理的程序,谁做过?能不能给点资料?源码更好……
- 哪位有翻译后的const.pas单元,我送其它常数单元给他
- 如何把TChart存为bmp文件
- 有没有谁熟悉这个ip的,高分相送219.130.136.58
然后在程序初始化的时候读取着两个东东
function SetADOConnection(user_id,datasource:string):boolean;
var
s:string;
begin
with ADOConnection1 do
begin
//可以先检测一下,是否有连接到其它数据库且应用程序正在使用中。
s:=' Provider=SQLOLEDB.1;Integrated Security=SSPI;'
s:=s+Persist Security Info=False;User ID='
s:=s+user_id+';Initial Catalog=dbStudentInfo;Data Source='+datasource
connected:=false;
ConnectionString:=s;
connected:=true; end;可以在表单上放两个EDIT来输入参数。可把连接设置好后用文本方式打开表单,拷贝出连接字串具体自己写吧
function SetADOConnection(user_id,datasource:string):boolean;
var
s:string;
begin
with ADOConnection1 do
begin
//可以先检测一下,是否有连接到其它数据库且应用程序正在使用中。
s:=' Provider=SQLOLEDB.1;Integrated Security=SSPI;'
s:=s+Persist Security Info=False;User ID='
s:=s+user_id+';Initial Catalog=dbStudentInfo;Data Source='+datasource
connected:=false;
ConnectionString:=s;
connected:=true;
end;
end;
function SetADOConnection(user_id,datasource:string):boolean;
var
s:string;
begin
with ADOConnection1 do
begin
//可以先检测一下,是否有连接到其它数据库且应用程序正在使用中。
s:=' Provider=SQLOLEDB.1;Integrated Security=SSPI;';
s:=s+Persist Security Info=False;User ID=';
s:=s+user_id+';Initial Catalog=dbStudentInfo;Data Source='+datasource;
connected:=false;
ConnectionString:=s;
connected:=true;
end;
end;
每次启动程序时从文本文件读入数据来设置
如下:procedure TForm1.FormCreate(Sender: TObject);
var
MyFile:textfile;
S1,s2:string;
begin
s2:='';
ADO1.Connected:=false;
assignfile(Myfile,'c:\a.txt');
reset(MyFile);
try
while not eof(Myfile) do
begin
readln(Myfile,S1);
if s2='' then s2:=trim(s1)
else s2=s2+trim(s1);
end;
ADOconnectin1.ConnectionString:=S2;
ADO1connection.Connected:=true;
finally
closefile(Myfile);
end;end;end.
大致如上,自己测试一下(可把连接字串拷贝到文本文件中,可分作几行)
procedure TForm1.FormCreate(Sender: TObject);
var
MyFile:textfile;
S1,s2:string;
begin
s2:='';
ADO1.Connected:=false;
assignfile(Myfile,'c:\a.txt');
reset(MyFile);
try
while not eof(Myfile) do
begin
readln(Myfile,S1);
if s2='' then s2:=trim(s1)
else s2:=s2+trim(s1);
end;
ADOconnectin1.ConnectionString:=S2;
ADO1connection.Connected:=true;
finally
closefile(Myfile);
end;end;end.
' Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=mjb;Initial Catalog=dbStudentInfo;Data Source=MJB ';
end;
要变的就是 User ID 和Data Source
我让 User ID =一个能得到用户名的函数,Date Source =GetComputerName(因为上面的MJB其实是我的机器名),可以吗
我分析你的需求不外两种
1、你的数据库有多个(相同数据库相当于多子公司的ERP),应用程序要在不同
公司间切换用我前面的方法可以搞定;
2、你的数据库服务器机器名或数据库名可能会改变,后面的方法也可搞定。
可能你的意思是数据库服务器机器名或数据库名改变后自动获取,但USERID、PASSWORD也可自动获取吗,如果有多数据库如何处理?