Fórum Conectar banco de dados via codigo #400382
05/05/2011
0
begin
case tip of
0 : begin
wconnection := 'FBConnection';
wdriver := 'Firebird';
wgetdriver := 'getSQLDriverINTERBASE';
wlibrary := 'dbxfb.dll';
wvendorlib := 'fbclient.dll';
end;
1 : begin
wconnection := 'IBConnection';
wdriver := 'Interbase';
wgetdriver := 'getSQLDriverINTERBASE';
wlibrary := 'dbxint.dll';
wvendorlib := 'gds32.dll';
end;
end; end;
A função acima estabelce qual a base de dado será conectada. procedure conexao;
begin
DM := TDM.Create(application);
With DM do
begin
conexao.ConnectionName := wconnection;
conexao.DriverName := wdriver;
conexao.GetDriverFunc := wgetdriver;
conexao.LibraryName := wlibrary;
conexao.LoginPrompt := false;
conexao.Params.Add('DataBase=nomedb');
conexao.VendorLib := wvendorlib;
try
conexao.Open;
except
begin
ShowMessage('Não foi possível efetuar a conexão.');
wresult := false;
end;
end;
end;
end; A procedure por sua vez realiza a conexão com o banco escolhido, nomedb é uma variavel do tipo string que recebe o comando onde esta armazenado o banco de dados. Ex: nomedb := 'G:\BacalaEditorSQL\BDteste.fdb', no caso essa linha de comando esta em um compontente edit. nomedb := txtlinhadecodigo.txt. Toda vez que tento testar, ele mostra a mensagem 'Não foi possível efetuar a conexão.' Alguem poderia me ajudar? Obrigado.
Wilton Júnior
Curtir tópico
+ 0Posts
05/05/2011
Rodrigo Mattos
Gostei + 0
06/05/2011
Wilton Júnior
Gostei + 0
08/05/2011
Jackson Veiga
Tente como no codigo abaixo:
procedure conexao;
begin
DM := TDM.Create(application);
With DM do
begin
conexão.Close; //não tenho certeza se é close, mas é algo parecido, o objetivo é fechar a conexão
//antes de reconectar.
conexao.ConnectionName := wconnection;
conexao.DriverName := wdriver;
conexao.GetDriverFunc := wgetdriver;
conexao.LibraryName := wlibrary;
conexao.LoginPrompt := false;
conexao.Params.Add('DataBase=nomedb');
conexao.VendorLib := wvendorlib;
try
conexao.Open;
except
begin
ShowMessage('Não foi possível efetuar a conexão.');
wresult := false;
end;
end;
end;
end;
Gostei + 0
09/05/2011
Wilton Júnior
Gostei + 0
09/05/2011
Wilton Júnior
Gostei + 0
09/05/2011
Wilton Júnior
Gostei + 0
09/05/2011
Wilton Júnior
Gostei + 0
09/05/2011
Wilton Júnior
Gostei + 0
09/05/2011
Rafael Mattos
Conexao.Params.Values['Database'] := 'Local do Seu Banco';
Gostei + 0
10/05/2011
Wilton Júnior
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)