Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

How to connect Ddatbase by dsn file

Avatar of turbot_yu
turbot_yuFlag for Singapore asked on
System Programming
6 Comments1 Solution421 ViewsLast Modified:
Originally, I use the following code to connect to DB, by connection string.

Now need to connect by .dsn file.

May I know how to do it? Now the DB changed to SQL2005

DataStruct OpenDatabase(char* DefServerName)
{
      DataStruct dbSession;
      SQLRETURN SQLinfo;
      bool connORA, connPML;

      SQLHENV    hEnv;
      SQLHDBC    hDbc;

      SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv );
      SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3,SQL_IS_INTEGER );
      SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc);
      SQLinfo = SQLConnect( hDbc,
            (SQLCHAR*)DefServerName,SQL_NTS,
            (SQLCHAR*)"pquser",SQL_NTS,
            (SQLCHAR*)"pquser",SQL_NTS );
      if( SQLinfo == SQL_SUCCESS || SQLinfo == SQL_SUCCESS_WITH_INFO )
            connORA = TRUE;
      else
            connORA = FALSE;

      SQLHENV    henv;
      SQLHDBC    hdbc;

      SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv );
      SQLSetEnvAttr( henv, SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3,SQL_IS_INTEGER );
      SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc);
      SQLinfo = SQLConnect( hdbc,
            (SQLCHAR*)PML_SYBASE,SQL_NTS,
            (SQLCHAR*)"LogSchema",SQL_NTS,
            (SQLCHAR*)"autonomy",SQL_NTS);
      if( SQLinfo == SQL_SUCCESS || SQLinfo == SQL_SUCCESS_WITH_INFO )
            connPML = TRUE;
      else
            connPML = FALSE;

      dbSession.hEnv  = hEnv;
      dbSession.hDbc  = hDbc;
      dbSession.henv  = henv;
      dbSession.hdbc  = hdbc;
      dbSession.connORA = connORA;
      dbSession.connPML = connPML;

      return dbSession;
}
ASKER CERTIFIED SOLUTION
Avatar of meenasree
meenasreeFlag of India image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answers