AI一個新的ODBC用戶DSN想使用戶DSN用下面的代碼的新條目,在ODBC數據源管理器:創建德爾福
procedure TForm1.FormCreate(Sender: TObject);
var strAttributes: string;
wideChars : array[0..1000] of WideChar;
pfErrorCode: DWORD;
errMsg: PChar;
begin
strAttributes := 'DSN=' + 'example_DSN' + Chr(0);
strAttributes := strAttributes + 'DESCRIPTION=' + 'description' + Chr(0);
strAttributes := strAttributes + 'SERVER=' + 'testserver' + Chr(0);
strAttributes := strAttributes + 'DATABASE=' + 'somedatabase' + Chr(0);
StringToWideChar(strAttributes, wideChars, 12);
if not SqlConfigDataSource(0, ODBC_ADD_DSN, 'SQL Server', wideChars) then
begin
errMsg := AllocMem(SQL_MAX_MESSAGE_LENGTH);
SQLInstallerError(1, @pfErrorCode, errMsg, SQL_MAX_MESSAGE_LENGTH, nil);
MessageBox(0, errMsg, PChar('Add System DSN Error #' + IntToStr(pfErrorCode)), 0);
FreeMem(errMsg);
end;
end;
但SqlConfigDataSource部分沒有做的工作,而且返回的錯誤不是undarstandable可言。這不是一個數字,也不是錯誤的描述。任何人都可以幫我解決我犯的錯誤嗎?謝謝
謝謝,就是這樣做的 – dzibul 2012-03-04 17:16:27