turbot_yu
asked on
how to use SQLDriverConnect
How to define the parameters.
SQLHENV hEnv;
SQLHDBC hDbc;
SQLHWND hwnd;
SQLSMALLINT SQL_NTS;
SQLCHAR * szOutConn;
SQLSMALLINT MAX_CONN_OUT;
SQLSMALLINT * cbOutConn;
//SQLUSMALLINT SQL_DRIVER_NOPROMPT;
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"FILEDSN=SQL_Se rver;Trust ed_Connect ion=yes""F ILEDSN=SQL _Server;Tr usted_Conn ection=yes "
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
but has error
C:\Documents and Settings\yuming\Desktop\Ev entDTP 20 Feb 2006_ run online_June2006\eventDTP.c pp(676) : error C2064: term does not evaluate to a function
C:\Documents and Settings\yuming\Desktop\Ev entDTP 20 Feb 2006_ run online_June2006\eventDTP.c pp(680) : error C2660: 'SQLDriverConnect' : function does not take 7 parameters
Error executing cl.exe.
SQLHENV hEnv;
SQLHDBC hDbc;
SQLHWND hwnd;
SQLSMALLINT SQL_NTS;
SQLCHAR * szOutConn;
SQLSMALLINT MAX_CONN_OUT;
SQLSMALLINT * cbOutConn;
//SQLUSMALLINT SQL_DRIVER_NOPROMPT;
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"FILEDSN=SQL_Se
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
but has error
C:\Documents and Settings\yuming\Desktop\Ev
C:\Documents and Settings\yuming\Desktop\Ev
Error executing cl.exe.
ASKER
thank, now I use this, compile no error, is it correct?
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"FILEDSN=SQL_Se rver.dsn;T rusted_Con nection=ye s",
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"FILEDSN=SQL_Se
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
ASKER
it cannot connect when running, does it need to specify the path of dsn file?
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"FILEDSN=SQL_HM I_Server.d sn;Trusted _Connectio n=yes",
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"FILEDSN=SQL_HM
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
Hi,
Check the Connection String You have given is currect or not .
it looks strange.
Deepu
Check the Connection String You have given is currect or not .
it looks strange.
Deepu
ASKER
I have a dsn file named SQL_HMI_Server.dsn under the path of C:\Program Files\Common Files\ODBC\Data Sources,
how to set the string?
how to set the string?
Hi,
What connection you are using.If it is ODBC it just Look Like this,
ODBC;DSN=odbcName;UID=user name;PWD=p assword; >> For Example
Deepu
What connection you are using.If it is ODBC it just Look Like this,
ODBC;DSN=odbcName;UID=user
Deepu
ASKER
I am using File DSN for ODBC connection, because I set the default DB in the dsn File
HI,
OK you are using ODBC right. Then You should specify the odbc name in the Control string.
Have you create the DSN(From Control Panels >>Administrative Tools >> ODBC)
If u havent yet, then create it first and give that DSN name to the Contrl string
Deepu
OK you are using ODBC right. Then You should specify the odbc name in the Control string.
Have you create the DSN(From Control Panels >>Administrative Tools >> ODBC)
If u havent yet, then create it first and give that DSN name to the Contrl string
Deepu
ASKER
From Control Panels >>Administrative Tools >> ODBC >> File DSN, I created a DSN file named SQL_Server.dsn, it saved in C:\Program Files\Common Files\ODBC\Data Sources
hi,
You just dont bother about the Path.
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;DSN=SQL_S erver.dsn; UID=sa;PWD =;Trusted_ Connection =yes;",
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
Give username and password(if present) to the Connection String
Deepu
You just dont bother about the Path.
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;DSN=SQL_S
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
Give username and password(if present) to the Connection String
Deepu
ASKER
still cannot,
In dsn file:
[ODBC]
DRIVER=SQL Native Client
UID=rmcs
PWD=rmcs
DATABASE=ming
WSID=HMI01
APP=Microsoft Data Access Components
SERVER=172.16.5.84\SQLEXPR ESS
In dsn file:
[ODBC]
DRIVER=SQL Native Client
UID=rmcs
PWD=rmcs
DATABASE=ming
WSID=HMI01
APP=Microsoft Data Access Components
SERVER=172.16.5.84\SQLEXPR
ASKER
Does it need to initailize the parameter?
SQLHENV hEnv;
SQLHDBC hDbc;
SQLHWND hwnd;
SQLSMALLINT SQL_NTS;
SQLCHAR * szOutConn;
SQLSMALLINT MAX_CONN_OUT;
SQLSMALLINT cbOutConn;
MAX_CONN_OUT=1000;
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv );
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION,(SQL POINTER)SQ L_OV_ODBC3 ,SQL_IS_IN TEGER );
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc);
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;DSN=SQL_S erver.dsn; UID=rmcs;P WD=rmcs;Tr usted_Conn ection=yes ", //;Trusted_Connection=yes" ,
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
SQLHENV hEnv;
SQLHDBC hDbc;
SQLHWND hwnd;
SQLSMALLINT SQL_NTS;
SQLCHAR * szOutConn;
SQLSMALLINT MAX_CONN_OUT;
SQLSMALLINT cbOutConn;
MAX_CONN_OUT=1000;
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv );
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION,(SQL
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc);
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;DSN=SQL_S
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
hi,
You have create a File DSN ,fine.Then you should give the path also.I have posted the above comments for System DSN(Sorry for confused you)
"ODBC;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\SQL_Server.dsn;UID =sa;PWD=;T rusted_Con nection=ye s;"
Deepu
You have create a File DSN ,fine.Then you should give the path also.I have posted the above comments for System DSN(Sorry for confused you)
"ODBC;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\SQL_Server.dsn;UID
Deepu
ASKER
still cannot, the return value is -1
Hi,
Try to use System DSN .I have already post the comment for that.You just check that if it works then we can make sure your code is fine.
Deepu
Try to use System DSN .I have already post the comment for that.You just check that if it works then we can make sure your code is fine.
Deepu
ASKER
Bebug before conncet
- &cbOutConn 0x0012d32c
-13108
hDbc 0x003c16f0
- &hDbc 0x0012d33c "ð<"
-16 'ð'
hEnv 0x003c1628
hwnd 0xcccccccc
MAX_CONN_OUT 1000
SQLinfo -13108
- szOutConn 0xcccccccc ""
CXX0030: Error: expression cannot be evaluated
After connect
- &cbOutConn 0x0012d32c
-13108
hDbc 0x003c16f0
hwnd 0xcccccccc
MAX_CONN_OUT 1000
SQLinfo -1
- szOutConn 0xcccccccc ""
CXX0030: Error: expression cannot be evaluated
- &cbOutConn 0x0012d32c
-13108
hDbc 0x003c16f0
- &hDbc 0x0012d33c "ð<"
-16 'ð'
hEnv 0x003c1628
hwnd 0xcccccccc
MAX_CONN_OUT 1000
SQLinfo -13108
- szOutConn 0xcccccccc ""
CXX0030: Error: expression cannot be evaluated
After connect
- &cbOutConn 0x0012d32c
-13108
hDbc 0x003c16f0
hwnd 0xcccccccc
MAX_CONN_OUT 1000
SQLinfo -1
- szOutConn 0xcccccccc ""
CXX0030: Error: expression cannot be evaluated
ASKER
Sysytem DSN cannot set default DB if more than 1 DB
ASKER
SQLHENV hEnv;
SQLHDBC hDbc;
SQLHWND hwnd;
SQLSMALLINT SQL_NTS;
SQLCHAR * szOutConn;
SQLSMALLINT MAX_CONN_OUT;
SQLSMALLINT cbOutConn;
MAX_CONN_OUT=1000;
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv );
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION,(SQL POINTER)SQ L_OV_ODBC3 ,SQL_IS_IN TEGER );
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc);
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;FILEDSN=C :\Program Files\Common Files\ODBC\Data Sources\SQL_Server.dsn;UID =rmcs;PWD= rmcs;Trust ed_Connect ion=yes", //;Trusted_Connection=yes" ,
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
SQLHDBC hDbc;
SQLHWND hwnd;
SQLSMALLINT SQL_NTS;
SQLCHAR * szOutConn;
SQLSMALLINT MAX_CONN_OUT;
SQLSMALLINT cbOutConn;
MAX_CONN_OUT=1000;
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv );
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION,(SQL
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc);
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;FILEDSN=C
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
ASKER
Will they affect
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv );
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION,(SQL POINTER)SQ L_OV_ODBC3 ,SQL_IS_IN TEGER );
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc);
SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv );
SQLSetEnvAttr( hEnv, SQL_ATTR_ODBC_VERSION,(SQL
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc);
ASKER
Will it affect
- szOutConn 0xcccccccc ""
CXX0030: Error: expression cannot be evaluated
- szOutConn 0xcccccccc ""
CXX0030: Error: expression cannot be evaluated
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
In file dsnj, it only give host name, then I can change host file in win to switch to dif server.
ASKER
I tried DSN, but runtime error occur before the connection line
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc); //Error LINE
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;DSN=aaa;U ID=rmcs;PW D=rmcs;Tru sted_Conne ction=yes" , //;Trusted_Connection=yes" ,
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
The Error is Unhandled Exception.
SQLAllocHandle( SQL_HANDLE_DBC, hEnv, &hDbc); //Error LINE
SQLinfo = SQLDriverConnect(
hDbc,
hwnd,
(SQLTCHAR*)"ODBC;DSN=aaa;U
SQL_NTS,
szOutConn,
MAX_CONN_OUT,
&cbOutConn,
SQL_DRIVER_NOPROMPT);
The Error is Unhandled Exception.
ASKER
ok,error solved, but still cannot connect by DSN.
Hi,
You mean in FILEDSN?
Deepu
You mean in FILEDSN?
Deepu
ASKER
no, the popup error solved but still cannot connect
ASKER
I use this one can conect,
SQLinfo = SQLConnect( hDbc,
(SQLCHAR*)"aaa",SQL_NTS,
(SQLCHAR*)"rmcs",SQL_NTS,
(SQLCHAR*)"rmcs",SQL_NTS );
but not sure whether it can switch DB
SQLinfo = SQLConnect( hDbc,
(SQLCHAR*)"aaa",SQL_NTS,
(SQLCHAR*)"rmcs",SQL_NTS,
(SQLCHAR*)"rmcs",SQL_NTS );
but not sure whether it can switch DB
hi,
Make sure your authetication given to the ODBC is Windows authetication
Deepu
Make sure your authetication given to the ODBC is Windows authetication
Deepu
ASKER
I am not using win Au.
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/cli/rzadpfndvcon.htm
The Following URL helps solve the Errors.
Please Go through it.It has an example code also
Deepu