這看起來像是一個奇怪的。MySQL連接提示輸入密碼,即使這是連接字符串
我有一個連接到MySQL數據庫的一個Pascal單元
unit u_MySQLConnection;
interface
uses
ADODB,
AnsiStrings,
Generics.Collections,
SysUtils,
DB
;
type
TMySQLConnection = class
strict private
mysqlCon : TADOConnection;
public
function Connect:boolean;
destructor Destroy;
end;
var
MySQLConnection : TMySQLConnection;
implementation
function TMySQLConnection.Connect:boolean;
var
success : boolean;
begin
success := true;
try
if NOT (mysqlCon = nil)
then mysqlCon.Destroy;
mysqlCon := TADOConnection.Create(nil);
mysqlCon.ConnectionString := 'DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=database; UID=root; PASSWORD=password;OPTION=3;';
except
success := false;
end;
Result := success;
end;
destructor TMySQLConnection.Destroy;
begin
FreeAndNil(mysqlCon);
inherited;
end;
end.
當我嘗試連接
MySQLConnection := TMySQLConnection.Create;
try
MySQLConnection.Connect;
finally
MySQLConnection.Destroy;
end;
我得到一個密碼,出現提示對話框,即使密碼已經在連接字符串中。如果我在此提示中輸入用戶名和密碼,其他一切正常。
事情就更有點怪怪的:
當我移動的數據庫連接命令到主.dpr文件,如
program DieselBatch;
uses
Vcl.Forms,
u_MySQLConnection in '..\src\u_MySQLConnection.pas'
(*,
frm_About in '..\src\frm_About.pas' {frmAbout},
frm_AnalystDetails in '..\src\frm_AnalystDetails.pas' {frmAnalystDetails},
frm_Batch in '..\src\frm_Batch.pas' {frmBatch},
frm_ConfirmResultsChanged in '..\src\frm_ConfirmResultsChanged.pas' {frmConfirmResultsChanged},
frm_DebugSample in '..\src\frm_DebugSample.pas' {frmDebugSample},
frm_FlashManualEntry in '..\src\frm_FlashManualEntry.pas' {frmFlashEntry},
frm_Main in '..\src\frm_Main.pas' {frmMain},
frm_SampleComment in '..\src\frm_SampleComment.pas' {frmSampleComment},
frm_SelectAnalystForResult in '..\src\frm_SelectAnalystForResult.pas' {frmSelectAnalystForResult},
u_Data in '..\src\u_Data.pas',
u_MicroCheck in '..\src\u_MicroCheck.pas',
u_Undo in '..\src\u_Undo.pas'
*)
;
{$R *.res}
var
MySQLConnection : TMySQLConnection;
begin
MySQLConnection := TMySQLConnection.Create;
try
MySQLConnection.Connect;
finally
MySQLConnection.Destroy;
end;
然後密碼提示不出現,只要這些單位被註釋掉。
當我再次註釋上述單位時,問題再次出現。
其中一些單位確實使用ADODB和DB,但我看不出單位的存在本身應該影響的MySqlConnection單元的水煤漿....
嘗試將'mysqlCon'的LoginPrompt設置爲false? – 2013-02-19 01:10:55
完成後:mysqlCon:= TADOConnection.Create(nil);添加mysqlcon.LoginPromt:= false; – Kutsoff 2013-02-19 03:43:24
密碼的ODBC屬性是PWD而不是PASSWORD,儘管mysql驅動程序也可能理解密碼。 – bohica 2013-02-19 09:02:11