Solved

VC++ Can connect to one SqlServer DB but not an other. Need help

Posted on 2006-11-29
20
412 Views
Last Modified: 2011-10-03
Hi,

I am working on a VC++ application and chaning it to use Windows Authentication to replace the old SqlServer Authentication.

I made changes in VC++ code and tested it agaist dev database and it works fine.
But the same changes don't work in a test database. I checked in test
that I have windows authentication id set up. I don't know what else
I can do.

below is the source code where it breaks. We use Rogue Wave to connect. The same code works fine for dev DB.

db = RWDBManager::database(      lpczServerType,                                                               lpczServerName,
                                                "",
                                                "",
                                                lpczDatabaseName);

The error msg I got is:
Vendor Library Error: Login incorrect.

I am really frustrated here.



0
Comment
Question by:jfz2004
  • 10
  • 7
  • 3
20 Comments
 
LVL 4

Expert Comment

by:hclgroup
ID: 18038775
Where are you specifying the username and password?
How is the windows credentials being passed to the SQL server?
0
 

Author Comment

by:jfz2004
ID: 18038809
Thanks.

I am passing in empty username/password for AD authentication:
OLD CODE:
            db = RWDBManager::database( lpczServerType,
                                                            lpczServerName,
                                                            lpczUserName,
                                                            lpczPassword,
                                                            lpczDatabaseName);

 

NEW CODE:
            db = RWDBManager::database( lpczServerType,
                                                            lpczServerName,
                                                            "",
                                                            "",
                                                            lpczDatabaseName);

And it works for my dev DB.

 

0
 
LVL 4

Expert Comment

by:hclgroup
ID: 18039319
Have you tried manually connecting to the test database using the windows credentials you are testing with?
0
 

Author Comment

by:jfz2004
ID: 18039384
How to manually connecting to the test database using the windows credentials?


Jennifer
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 18039409
You can do that using query analyser?

For me its under
Start --> Programs --> Microsoft SQL Server
0
 

Author Comment

by:jfz2004
ID: 18039461
I have query analyser. What should I do in analyser?


Thanks,

Jennifer
0
 

Author Comment

by:jfz2004
ID: 18039497
Ok. I just tested that I can mannually connect to my test DB using Windows Authentication.

Jennifer
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 18039535
1) you launch Query Analyser
2) Select the server you want to connect to
3) Select Windows Authentication
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 18039547
Do you have permissions for the database you are connecting to?
0
 

Author Comment

by:jfz2004
ID: 18039584
Thanks.
I just tested that I can mannually connect to my test DB using Windows Authentication without any problem.

I checked in the sqlserver error log and found this error msg:


"login failed for user '(NULL)' reason : not associated with trusted sqlserver connection."

Jennifer
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 4

Expert Comment

by:hclgroup
ID: 18039653
Are you using a local windows account or a domain account?
Is the test server on a remote machine or the local machine?
0
 

Author Comment

by:jfz2004
ID: 18039668
1. I am using a network windows account, like "abcs\myuserid".
2. The server is on a remote machine.


Jennifer
0
 

Author Comment

by:jfz2004
ID: 18039855
My dev DB is SqlServer 2000 and my test DB is SqlServer 2003.

My VC++ is compiled in Visual Studio 6.

Jennifer
0
 

Author Comment

by:jfz2004
ID: 18040289
Also, My dev DB is in a different domain than my test DB.

Any idea?

Jennifer
0
 

Author Comment

by:jfz2004
ID: 18040616
Another thing to note:
I use Rogue Wave SPM to open connection:

RWBoolean
RWDBMsDbLibSystemHandle::open()
{
    dbproc_ = dbopen(loginrec_, (char*)(const char*)serverName_);
    if (dbproc_) {
    // use the designated DB, if supplied
        if ( dbName_.isNull() )
            return TRUE;                // not supplied
        if ( dbuse(dbproc_, (char *)(const char*)dbName_) == SUCCEED )
            return TRUE;
    // couldn't use the designated DB, so close everything
        close();
    }
    return FALSE;
}
0
 
LVL 2

Accepted Solution

by:
mekanoo earned 250 total points
ID: 18052850
if you use windows authentification the username and password are not "" "" -

"login failed for user '(NULL)' reason : not associated with trusted sqlserver connection."

>> you have to pass a username
- so create one that has all the rights  that are needed and pass it over on your login...
username "" = NULL = nobody

in rogue wave manual you can read that username is expected - it looks that they don't support windows authentification....

::::::
2.2 Databases and Connections

In order for a SourcePro DB application to open and use the connections required for interacting with a database, create an RWDBDatabase instance by calling:

RWDBManager::database(accessLib, serverName, userName,
                      passWord, databaseName);

These arguments, which are all of type RWCString, are used to build a connect string that is passed to the ODBC API function SQLDriverConnect(). This string takes the form:

DSN=serverName; PWD=passWord; DB=databaseName; UID=userName

The arguments you must provide to RWDBManager::database() are:

    *

      accessLib: If your DB Access Module for Microsoft SQL Server is compiled as a DLL or shared library, provide the name of the DLL or shared library. See the document Building Your Applications for information about naming conventions. If you are using a static library, supply the string "MS_SQL".
    *

      serverName: Supply the name of the SQL Server ODBC data source to which you are connecting, as found in the ODBC control panel. Or, for direct control of connection parameters, pass a full connect string of the form required by SQLDriverConnect(); for example:

      "DSN=someDataSource;UID=user;PWD=password"

      In this case, the string is passed to SQLDriverConnect() without modification, and the userName, passWord, and databaseName parameters are ignored.
    *

      userName: Supply the login of a valid user. Depending on the ODBC SQL Server data source settings, this may or may not be optional.
    *

      passWord: Supply the password for the user specified by userName. Depending on the Microsoft SQL Server ODBC data source settings, this may or may not be optional.
    *

      databaseName: You can optionally supply the name of a SQL server database to use. If this parameter is not supplied, the default database of the specified user is used.

Here are three examples of opening a database on a specific SQL server, INHOUSE.

    *

      The first example opens a specific database, ACCOUNTING. Notice that the accessLib is defined as MS_SQL, indicating that the application must be linked with the static version of the Access Module:

RWDBManager::database("MS_SQL", "INHOUSE",
                      "cratchitt","scrooge","ACCOUNTING");

    *

      The second example shows opening the same database from a Windows application. In this case, the accessLib is defined as msq424d.dll, indicating that the application will dynamically load the Access Module at runtime:

RWDBManager::database("msq424d.dll", "INHOUSE",
                      "cratchitt","scrooge","ACCOUNTING");

    *

      The third example demonstrates how to open a user's default database, which is the database assigned to the user by the database administrator:

RWDBManager::database("msq424d.dll", "INHOUSE",
                      "cratchitt", "scrooge", "");

    *

      The final example demonstrates opening the database from a UNIX application. The parameter for the server name when creating the RWDBDatabase -> object may be either the IP Address of your SQL Server, or the DNS name. If no port is specified with the server name, SourcePro DB defaults to port 1433.

RWDBManager::database("MS_SQL", "192.168.1.1",
                      "cratchitt","scrooge","ACCOUNTING");

      Connects to the server at 192.168.1.1,1433.

RWDBManager::database("msq534d.so", "192.168.1.1,1212",
                      "cratchitt","scrooge","ACCOUNTING");

      Connects to the server at 192.168.1.1,1212.
0
 
LVL 4

Expert Comment

by:hclgroup
ID: 18053546
mekanoo : If that's the case then how come it works on DEV server?
0
 
LVL 2

Expert Comment

by:mekanoo
ID: 18054750
if the DEV Server is the same computer your'e already loggedin- then the authentification is passed over by the system..
0
 

Author Comment

by:jfz2004
ID: 18056667
Thanks everyone and especially thank you, mekanoo.

I will test what you said and see what happens. Will soon get back here.

Again, I am very grateful for your help.

Jennifer
0
 
LVL 2

Expert Comment

by:mekanoo
ID: 18080395
Thanks for the points - Jennifer !

it's a true pleasure to proof ones skills here -

good luck & best wishes from germany@lakeofconstance

mekanoo
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

13 Experts available now in Live!

Get 1:1 Help Now