Arsip: Ubah MyODBC dengan Delphi7

 
user image
more 12 years ago

onsir

Tanya: Bagaimana caranya membuat atau merubah konfigurasi MyODBC dari Delphi7 pada saat running. Cth: saya sdh buat odbc CobaODBC, lalu ingin saya ubah nama server dan databasenya dari Delphi. Database yang digunakan MySQL dan SQL Server Saya mempunyai modifikasi code spt di bawah ini, tetapi masih salah. Mohon bantuan teman-teman programmer. Atas jawabannya saya ucapkan terima kasih. unit OdbcConfig; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Db, DBTables; function SQLConfigDataSource (HwndParent:THandle; fRequest:integer; Driver, DSN,Host,DB,Usr,PWD:PChar; Port:Integer):integer;stdcall;external 'MyODBC.dll'; type TODBC_Command = (ODBC_NO_COMMAND, ODBC_ADD_DSN, ODBC_CONFIG_DSN, ODBC_REMOVE_DSN, ODBC_ADD_SYS_DSN, ODBC_CONFIG_SYS_DSN, ODBC_REMOVE_SYS_DSN); type TDSN = class public class function CreateMySQLDSN(DSNName,Host,Database,User,PWD:String; Port:Integer):integer; class function DeleteMySQLDSN(DSNName,Host,Database,User,PWD:String; Port:Integer):integer; end; implementation //class function TDSN.CreateMSAccessDSN(DSNName, path:String):integer; class function TDSN.CreateMySQLDSN(DSNName,Host,Database,User,PWD:String; Port:Integer):integer; begin // Result := SQLConfigDataSource(0, Ord(ODBC_ADD_SYS_DSN), 'Microsoft Access Driver (*.mdb)', Pchar('DSN='+DSNName+#0+'FIL=MS ACCESS'+#0+'DBQ='+path+#0)); //function SQLConfigDataSource (HwndParent:THandle; fRequest:integer; Driver, DSN,Host,DB,Usr,PWD:PChar; Port:Integer):integer;stdcall;external 'MyODBC.dll'; //Libmysql.dll'; Result:=SQLConfigDataSource(0,Ord(ODBC_ADD_SYS_DSN), 'MySQL', Pchar('DSN='+DSNName), Pchar('Host='+Host), Pchar('Database='+Database), Pchar('User='+User), Pchar('PWD='+PWD),Port); { Result:=SQLConfigDataSource(0,Ord(ODBC_ADD_SYS_DSN), 'MySQL', Pchar('DSN='+DSNName+#0+'FIL=MySQL'+#0+'DBQ='+Host+#0), Pchar('Host='+Database+#0+'FIL=MySQL'+#0+'DBQ='+Database+#0), Pchar('DSN='+User+#0+'FIL=MySQL'+#0+'DBQ='+User+#0), (Pchar('DSN='+PWD+#0+'FIL=MySQL'+#0+'DBQ='+PWD+#0))); } end; class function TDSN.DeleteMySQLDSN(DSNName,Host,Database,User,PWD:String; Port:Integer):integer; begin Result:=SQLConfigDataSource(0,Ord(ODBC_ADD_SYS_DSN),'MySQL', Pchar('DSN='+DSNName), Pchar('Host='+Host), Pchar('Database='+Database), Pchar('User='+User), Pchar('PWD='+PWD),Port); end; end.
user image
more 12 years ago

_lmz

@onsir: function SQLConfigDataSource (HwndParent:THandle; fRequest:integer; Driver, DSN,Host,DB,Usr,PWD:PChar; Port:Integer):integer;stdcall;external 'MyODBC.dll'; ... Result:=SQLConfigDataSource(0,Ord(ODBC_ADD_SYS_DSN), 'MySQL', Pchar('DSN='+DSNName), Pchar('Host='+Host), Pchar('Database='+Database), Pchar('User='+User), Pchar('PWD='+PWD),Port);
Ada alasan tertentu anda yakin bahwa prototype SQLConfigDataSource seperti itu? Karena dari platform SDK: BOOL SQLConfigDataSource( HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes); dari odbcinst.h: BOOL INSTAPI SQLConfigDataSource (HWND hwndParent, WORD fRequest, LPCSTR lpszDriver, LPCSTR lpszAttributes); Di mana INSTAPI adalah __stdcall. Jadi stdcallnya sudah benar, tapi parameternya mungkin cuma 4 saja. Kenapa anda pakai DLL drivernya mysql? Berdasarkan tracing ODBC Data Source Administrator, fungsi SQLConfigDataSource ada di "odbccp32.dll". Format atribut juga tidak seperti itu:
ConfigDSN receives connection information from the installer DLL as a list of attributes in the form of keyword-value pairs. Each pair is terminated with a null byte, and the entire list is terminated with a null byte. (That is, two null bytes mark the end of the list.) Spaces are not allowed around the equal sign in the keyword-value pair. ... For example, to configure a data source that requires a user ID, password, and database name, a setup application might pass the following keyword-value pairs: DSN=Personnel Data\0UID=Smith\0PWD=Sesame\0DATABASE=Personnel\0\0
Contoh: http://www.arcknowledge.com/gmane.comp.db.mysql.odbc/2003-02/msg00086.html
user image
more 12 years ago

belajaraja

sebaiknya dibuat satu form aja mas sendiri untuk konfigurasi, kemudian nanti di save di .txt. jadi nanti kalo running dan mau dirubah konfigurasi nyatinggal buka aja itu form kemudian secara default ketika form itu open membaca konfigurasi yang sudah mas simpan di .txt tersebut, jadi mas bisa rubah* sesuka mas...
user image
more 12 years ago

pebbie

klo saya sih, ubah aja di registry.. cari aja tutorial dynamic ODBC untuk lokasi setting ODBC di registry.
more ...
  • Pages:
  • 1
Share to

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com