Fórum Configurar ODBC via programação #344472
14/08/2007
0
Alguém sabe configurar o driver ODBC para sybase via programação Delphi. Eu achei um exemplo com Acess e não consegui fazer para o sybase.
Acacio
Curtir tópico
+ 0
Responder
Posts
14/08/2007
Acacio
Achei uma função aqui CreateODBCDriver ela cria as configurações no ODBC, mas só para Acess queria utilizar ela no sybase ou em outro tipo de banco qualquer.
A função abaixo, Se alguém souber configurar para ´sybase´.
procedure TConfiguraDraverODBC.CreateODBCDriver(const cDSNName, cExclusive,
cDescription, cDataBase, cDefaultPath, cConfigSql, cDriver: string);
//
// Cria um Driver no ODBC
//
// Deve ser usado da seguinte forma
//
// CreateOdbcDriver(´TestDSN´,´1´,´Test Data´,´TestData.MDB´,´ODBCCP32´,´SQLConfigDataSource´,´Microsoft Access Driver (*.mdb)´);
//
type
TSQLConfigDataSource = function( hwndParent: HWND; fRequest: WORD; lpszDriver: LPCSTR; lpszAttributes: LPCSTR ): BOOL; stdcall;
const
ODBC_ADD_DSN = 1; // Add data source
ODBC_CONFIG_DSN = 2; // Configure (edit) data source
ODBC_REMOVE_DSN = 3; // Remove data source
ODBC_ADD_SYS_DSN = 4; // add a system DSN
ODBC_CONFIG_SYS_DSN = 5; // Configure a system DSN
ODBC_REMOVE_SYS_DSN = 6; // remove a system DSN
var
pFn: TSQLConfigDataSource;
hLib: LongWord;
strDriver: string;
strHome: string;
strAttr: string;
strFile: string;
fResult: BOOL;
ModName: array[0..MAX_PATH] of Char;
srInfo : TSearchRec;
begin
Windows.GetModuleFileName( HInstance, ModName, SizeOf(ModName) );
strHome := ModName;
while ( strHome[length(strHome)] <> ´\´ ) do
Delete( strHome, length(strHome), 1 );
strFile := strHome + cDatabase; // Test Access Rights (Axes = Access)
hLib := LoadLibrary( pChar(cDefaultPath) ); // load from default path
if( hLib <> NULL ) then
begin
@pFn := GetProcAddress( hLib, pChar(cConfigSql) );
if( @pFn <> nil ) then
begin
// force (re-)create DSN
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+#0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description=¬s´+0+0,
[cDSNName,strFile,cExclusive,cDescription] );
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Create DSN (Datasource) failed!´ );
// test/create MDB file associated with DSN
if( FindFirst( strFile, 0, srInfo ) <> 0 ) then
begin
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description= ¬s´+0+0+
´CREATE_DB=´¬s´´0+0,
[cDSNName,strFile,cExclusive,cDescription,strFile]);
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Create DFB (Database file) failed!´ );
end;
FindClose( srInfo );
end;
FreeLibrary( hLib );
if fResult then
ShowMessage( ´Create FDB (Database file) Sucefull created!´ );
end
else
begin
ShowMessage( ´Unable to load IscDbc.DLL´ );
end;
end;
A função abaixo, Se alguém souber configurar para ´sybase´.
procedure TConfiguraDraverODBC.CreateODBCDriver(const cDSNName, cExclusive,
cDescription, cDataBase, cDefaultPath, cConfigSql, cDriver: string);
//
// Cria um Driver no ODBC
//
// Deve ser usado da seguinte forma
//
// CreateOdbcDriver(´TestDSN´,´1´,´Test Data´,´TestData.MDB´,´ODBCCP32´,´SQLConfigDataSource´,´Microsoft Access Driver (*.mdb)´);
//
type
TSQLConfigDataSource = function( hwndParent: HWND; fRequest: WORD; lpszDriver: LPCSTR; lpszAttributes: LPCSTR ): BOOL; stdcall;
const
ODBC_ADD_DSN = 1; // Add data source
ODBC_CONFIG_DSN = 2; // Configure (edit) data source
ODBC_REMOVE_DSN = 3; // Remove data source
ODBC_ADD_SYS_DSN = 4; // add a system DSN
ODBC_CONFIG_SYS_DSN = 5; // Configure a system DSN
ODBC_REMOVE_SYS_DSN = 6; // remove a system DSN
var
pFn: TSQLConfigDataSource;
hLib: LongWord;
strDriver: string;
strHome: string;
strAttr: string;
strFile: string;
fResult: BOOL;
ModName: array[0..MAX_PATH] of Char;
srInfo : TSearchRec;
begin
Windows.GetModuleFileName( HInstance, ModName, SizeOf(ModName) );
strHome := ModName;
while ( strHome[length(strHome)] <> ´\´ ) do
Delete( strHome, length(strHome), 1 );
strFile := strHome + cDatabase; // Test Access Rights (Axes = Access)
hLib := LoadLibrary( pChar(cDefaultPath) ); // load from default path
if( hLib <> NULL ) then
begin
@pFn := GetProcAddress( hLib, pChar(cConfigSql) );
if( @pFn <> nil ) then
begin
// force (re-)create DSN
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+#0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description=¬s´+0+0,
[cDSNName,strFile,cExclusive,cDescription] );
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Create DSN (Datasource) failed!´ );
// test/create MDB file associated with DSN
if( FindFirst( strFile, 0, srInfo ) <> 0 ) then
begin
strDriver := cDriver;
strAttr := Format( ´DSN=¬s´+0+
´DBQ=¬s´+0+
´Exclusive=¬s´+0+
´Description= ¬s´+0+0+
´CREATE_DB=´¬s´´0+0,
[cDSNName,strFile,cExclusive,cDescription,strFile]);
fResult := pFn( 0, ODBC_ADD_SYS_DSN, @strDriver[1], @strAttr[1] );
if( fResult = false ) then
ShowMessage( ´Create DFB (Database file) failed!´ );
end;
FindClose( srInfo );
end;
FreeLibrary( hLib );
if fResult then
ShowMessage( ´Create FDB (Database file) Sucefull created!´ );
end
else
begin
ShowMessage( ´Unable to load IscDbc.DLL´ );
end;
end;
Responder
Gostei + 0
14/08/2007
José Henrique
Veja se isto ajuda
http://www.connectionstrings.com/?carrier=sybase
http://www.connectionstrings.com/?carrier=sybase
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)