• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

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

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
jfz2004
Asked:
jfz2004
  • 10
  • 7
  • 3
1 Solution
 
hclgroupCommented:
Where are you specifying the username and password?
How is the windows credentials being passed to the SQL server?
0
 
jfz2004Author Commented:
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
 
hclgroupCommented:
Have you tried manually connecting to the test database using the windows credentials you are testing with?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
jfz2004Author Commented:
How to manually connecting to the test database using the windows credentials?


Jennifer
0
 
hclgroupCommented:
You can do that using query analyser?

For me its under
Start --> Programs --> Microsoft SQL Server
0
 
jfz2004Author Commented:
I have query analyser. What should I do in analyser?


Thanks,

Jennifer
0
 
jfz2004Author Commented:
Ok. I just tested that I can mannually connect to my test DB using Windows Authentication.

Jennifer
0
 
hclgroupCommented:
1) you launch Query Analyser
2) Select the server you want to connect to
3) Select Windows Authentication
0
 
hclgroupCommented:
Do you have permissions for the database you are connecting to?
0
 
jfz2004Author Commented:
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
 
hclgroupCommented:
Are you using a local windows account or a domain account?
Is the test server on a remote machine or the local machine?
0
 
jfz2004Author Commented:
1. I am using a network windows account, like "abcs\myuserid".
2. The server is on a remote machine.


Jennifer
0
 
jfz2004Author Commented:
My dev DB is SqlServer 2000 and my test DB is SqlServer 2003.

My VC++ is compiled in Visual Studio 6.

Jennifer
0
 
jfz2004Author Commented:
Also, My dev DB is in a different domain than my test DB.

Any idea?

Jennifer
0
 
jfz2004Author Commented:
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
 
mekanooCommented:
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
 
hclgroupCommented:
mekanoo : If that's the case then how come it works on DEV server?
0
 
mekanooCommented:
if the DEV Server is the same computer your'e already loggedin- then the authentification is passed over by the system..
0
 
jfz2004Author Commented:
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
 
mekanooCommented:
Thanks for the points - Jennifer !

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

good luck & best wishes from germany@lakeofconstance

mekanoo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 10
  • 7
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now