AI đang cố gắng để thực hiện một mục mới trong User DSN, trong ODBC Data Source Administrator mới có đoạn mã sau:tạo ra một DSN sử dụng ODBC mới với Delphi
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;
nhưng phần SqlConfigDataSource không thực hiện công việc, và cả lỗi được trả về cũng không thể hiểu được. Nó không phải là một số, cũng không phải là mô tả cho lỗi. Bất cứ ai có thể giúp tôi, nơi tôi làm cho những sai lầm? Cảm ơn
cảm ơn, điều đó đã làm – dzibul