我做了一个nt服务,用TADOConnection连接数据库,如果在控件的ConnectionString属性添上连接字符串,连接成功。如果在程序中填写则连接失败!为什么?谢谢!在线等......
是不是nt服务程序不允许动态的配置ConnectionString属性。
在程序中是这样写的:....... adoConn.Close;
adoConn.LoginPrompt := False;
adoConn.ConnectionString := 'Provider=SQLOLEDB.1;Password=;Persist Security Info=False;User ID=sa;Initial Catalog=HPMediator;Data Source=LIMENGYAN'; try
adoConn.Connected := True;
Result := 0;
WriteLog('read db ok', 'error_db');
except
if adoConn.Connected = False then
Result := -1
else
Result := -3;
WriteLog('read db error ' + adoConn.ConnectionString, 'error_db');
end;.........
是不是nt服务程序不允许动态的配置ConnectionString属性。
在程序中是这样写的:....... adoConn.Close;
adoConn.LoginPrompt := False;
adoConn.ConnectionString := 'Provider=SQLOLEDB.1;Password=;Persist Security Info=False;User ID=sa;Initial Catalog=HPMediator;Data Source=LIMENGYAN'; try
adoConn.Connected := True;
Result := 0;
WriteLog('read db ok', 'error_db');
except
if adoConn.Connected = False then
Result := -1
else
Result := -3;
WriteLog('read db error ' + adoConn.ConnectionString, 'error_db');
end;.........
procedure TCustomConnection.SetConnected(Value: Boolean);
begin
if (csReading in ComponentState) and Value then
FStreamedConnected := True else
begin
if Value = GetConnected then Exit;
if Value then
begin
if Assigned(BeforeConnect) then BeforeConnect(Self);
DoConnect;
SendConnectEvent(True);
if Assigned(AfterConnect) then AfterConnect(Self);
end else
begin
if Assigned(BeforeDisconnect) then BeforeDisconnect(Self);
SendConnectEvent(False);
DoDisconnect;
if Assigned(AfterDisconnect) then AfterDisconnect(Self);
end;
end;
end;呵呵,最好的方法还是用open函数来打开。
在控件的ConnectionString属性设置连接成功后,用Showmessage()查看一下
然后动态设置的时候再Showmessage一下动态设置的ConnectionString,看看两次有什么不同如果有,那就最好,你可以照着修改动态的那个了如果相同,那就只有升级MDAC了,看看能不能成功