Arsip: Ubah MyODBC dengan Delphi7

more 15 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.

more 15 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\0Contoh: http://www.arcknowledge.com/gmane.comp.db.mysql.odbc/2003-02/msg00086.html

more 15 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...

more 15 years ago
pebbie
klo saya sih, ubah aja di registry.. cari aja tutorial dynamic ODBC untuk lokasi setting ODBC di registry.
more ...
- Pages:
- 1
reply |
Report Obsolete
Last Articles
Last Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 1 years ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 1 years ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 1 years ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 1 years ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 1 years ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 1 years ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 2 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 9 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 9 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 9 years ago
Random Topic
- Mohon Bantuan ERROR CODE "$2601 (9729) = Key violation
by crazy_einstein01 in Bedah Kasus more 14 years ago - Form tumpuk2 ilang2 bingung2, tolong2 ya
by joudie in Hal umum tentang Pascal Indonesia more 13 years ago - Cara Memanggil File pada delphi
by ilhuna in Lain-lain more 11 years ago - Install JEDI di Turbo Delphi Explorer
by bangfauzan in Tip n Trik Pemrograman more 15 years ago - Borland Kylix Linux
by palinggi in Hal umum tentang Pascal Indonesia more 15 years ago - Introducing MORFIK
by simba in Free dan Gratis more 15 years ago - Masukkin data time dgn mask edit???
by camp_sire in Tip n Trik Pemrograman more 14 years ago - delphi-id gak bisa diakses dari beberapa lokasi
by simba in Hal umum tentang Pascal Indonesia more 14 years ago - Preview Quick Report
by vikraa in Reporting more 15 years ago - Create Form saat Runtime
by uGLy in Form Enhancement & Graphical Controls more 15 years ago