Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7618857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:30:46+00:00 2026-05-31T03:30:46+00:00

AI am trying to make a new entry in User DSN, in ODBC Data

  • 0

AI am trying to make a new entry in User DSN, in ODBC Data Source Administrator with the following code:

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;

but the SqlConfigDataSource part does not do the job, and also the error that is returned is not undarstandable at all. It is not a number, nor description for the error. Can anyone help me where i make the mistake? Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:30:47+00:00Added an answer on May 31, 2026 at 3:30 am

    Probably your error or even set of errors is in incorrect translation of ODBC headers, which then may be used for non-Unicode or Unicode Delphi version. For example:

    • for Unicode Delphi you rather need to use XxxW (UTF16) functions from ODBCCP32.DLL, than Xxx (ANSI) functions;
    • for non-Unicode Delphi rather Xxx functions. And then wideChars should be defined as array[..] of Char;
    • SqlConfigDataSource may be defined as XxxW with PAnsiChar;
    • etc.

    I wanted to show you the idea, because without full sources I can only speculate. Then you have suspicious call StringToWideChar(strAttributes, wideChars, 12);. strAttributes value is much more long than 12 characters.

    The following code works well in Delphi XE2:

    type
      SQLHWnd = LongWord;
      SQLChar = Char;
      PSQLChar = ^SQLChar;
      SQLBOOL = WordBool;
      UDword = LongInt;
      PUDword = ^UDword;
      SQLSmallint = Smallint;
      SQLReturn = SQLSmallint;
    
    const
      SQL_MAX_MESSAGE_LENGTH = 4096;
    
      ODBC_ADD_DSN     = 1;         // Add data source
      ODBC_CONFIG_DSN  = 2;         // Configure (edit) data source
      ODBC_REMOVE_DSN  = 3;         // Remove data source
    
      ODBC_ADD_SYS_DSN    = 4;          // add a system DSN
      ODBC_CONFIG_SYS_DSN   = 5;        // Configure a system DSN
      ODBC_REMOVE_SYS_DSN   = 6;        // remove a system DSN
      ODBC_REMOVE_DEFAULT_DSN   = 7;    // remove the default DSN
    
    function SQLConfigDataSource (
        hwndParent:     SQLHWnd;
        fRequest:       WORD;
        lpszDriver:     PChar;
        lpszAttributes: PChar
      ): SQLBOOL; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
      external 'odbccp32.dll' name 'SQLConfigDataSourceW';
    
    function SQLInstallerError (
        iError:           WORD;
        pfErrorCode:      PUDword;
        lpszErrorMsg:     PChar;
        cbErrorMsgMax:    WORD;
        pcbErrorMsg:      PWORD
      ): SQLReturn; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
      external 'odbccp32.dll' name 'SQLInstallerErrorW';
    
    procedure TForm616.Button1Click(Sender: TObject);
    var
      strAttributes: string;
      pfErrorCode: UDword;
      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);
      if not SqlConfigDataSource(0, ODBC_ADD_DSN, 'SQL Server', PChar(strAttributes)) 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;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new MVC user and I am trying to make shopping cart as
I'm trying to make a new CLLocation subclass. This is the skeleton: #import <UIKit/UIKit.h>
I'm trying to make a new wx.Choice-like control (actually a replacement for wx.Choice) which
I work for a company and am trying to make a new demo page.
I don't know alot about ASP.Net but I'm trying to make a new control
I'm new to BIRT and I'm trying to make the Report Engine running. I'm
I am trying to make a copy of a database to a new database
I am trying to make a firefox extension which looks at all the new
I am trying to make a blackjack game where before each new round, the
I am trying to make a simple program that could open a new activity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.