PowerBuilder / SQL Server / NT Authentication

Posted on 2005-04-05
Last Modified: 2013-12-26
I've assigned 500 because this is a fairly urgent question.  We're using PowerBuilder 8 at the moment but can upgrade to 10 if need be.  We need to connect to a SQL Server and have that connection run through NT authentication instead of using a SQL user.  I tried while setting up the connection to leave the username/password blank hoping that it would then default to the NT Authentication from the user logged into the machine but it did not.  I need to know step by step how to go about doing this.  Thanks in advance.
Question by:IUFITS
    LVL 18

    Accepted Solution

    hi ,
    Please refer the URL... it is very helpful for u...

    to make things short.... add the following code in ur application open event... it will create a DSN for u dynamically and u can connect to SQL Server thru NT authentication(provided the username has rights on SQL Server )

    // Define the following as the Global External Function in the application
    Function boolean GetUserNameA( ref string userID, ref ulong len ) library "ADVAPI32.DLL"

    //Write the following code in application Open Event....

    // set system dsn

    string  login_name
    string  ls_temp
    ulong   lul_value
    boolean lb_rc

    lul_value = 255
    ls_temp = Space( 255 )
    lb_rc = GetUserNameA( ls_temp, lul_value )
    login_name = Trim( ls_temp )

    // login_name will return the windows username who has logged onto the machine
    // If the username has rights on SQL Server he can successfully login using windows authentication


    // if u want SQL server authentication (NOT NT authentication) ignore the above 2 lines and add the following line..

    SQLCA.AutoCommit = False
    SQLCA.DBParm = "ConnectString='DSN=security_sql"

    Connect using SQLCA;
    //code ends here

    the above code will create ur DSN 'security_sql' on the machine if it doesn't find the same else it will overwrite the DSN.... the code is tested and works fine.... if u r still encountering any error please state the error so i can help... ask if u need more clarity...

    LVL 3

    Author Comment

    Our users won't have access to write to the registry (this application goes outside of our active directory OU but not out of the domain) so I'm going to attempt to take the DSN you create and keep it in the program.  I'll report back cause I'm sure I'll have a question but that was a great post Rosh, thanks!
    LVL 5

    Expert Comment

    You don't mention which interface you are using (ODBC, MSS, OLEDB).  Have you tried adding 'Secure=1' in the dbparm of the transaction object?  That is all you need for MSS.
    LVL 18

    Expert Comment


    do u need any more assistance???

    LVL 3

    Author Comment

    I'll be able to update you hopefully later today.  Thanks for the patience.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now