SQLConnect
Apr 14, 2008
didn't know where else to put this question.
I am trying to connect to an access database via ODBC using SQLConnect call. It works fine in an exe. Though, when I try to launch it from a DLL after DLL_PROCESS_ATTACH, the function hangs and never returns. What am I missing?
View 3 Replies
Sep 16, 2007
Hi,
I'm using the SQLconnect function in order to connect to my SQL server
I want to connect to a database called "CookieJar" without user name and password
this is the code:
#include "Container.h"
#include <windows.h>
#include <sqlext.h>
int main()
{
HENV hEnv = NULL; // Env Handle from SQLAllocEnv()
HDBC hDBC = NULL; // Connection handle
HSTMT hStmt = NULL;// Statement handle
UCHAR szDSN[1024] = "CookieJar";// Data Source Name buffer
UCHAR szUID[10] = "";// User ID buffer
UCHAR szPasswd[10] = "";// Password buffer
UCHAR szModel[128];// Model buffer
SDWORD cbModel;// Model buffer bytes recieved
char buff[9] = "Testing";
UCHAR szSqlStr[128]= "INSERT into (Tablename) (ColumnName) Values ('Testing')" ;
RETCODE retcode;
//sprintf((char*)szSqlStr,"INSERT into (Tablename)(Columname) Values ('%s')",buff);
// Allocate memory for ODBC Environment handle
SQLAllocEnv (&hEnv);
// Allocate memory for the connection handle
SQLAllocConnect (hEnv, &hDBC);
// Connect to the data source "test" using userid and password.
retcode = SQLConnect (hDBC, (SQLWCHAR*)szDSN, SQL_NTS,/* (SQLWCHAR*)szUID*/ NULL, SQL_NTS, /*(SQLWCHAR*)szPasswd*/ NULL, SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
// Allocate memory for the statement handle
retcode = SQLAllocStmt (hDBC, &hStmt);
// Prepare the SQL statement by assigning it to the statement handle
retcode = SQLPrepare (hStmt, (SQLWCHAR*)szSqlStr, sizeof (szSqlStr));
// Execute the SQL statement handle
retcode = SQLExecute (hStmt);
// Project only column 1 which is the models
SQLBindCol (hStmt, 1, SQL_C_CHAR, szModel, sizeof(szModel), &cbModel);
// Get row of data from the result set defined above in the statement
retcode = SQLFetch (hStmt);
// Free the allocated statement handle
SQLFreeStmt (hStmt, SQL_DROP);
// Disconnect from datasource
SQLDisconnect (hDBC);
}
// Free the allocated connection handle
SQLFreeConnect (hDBC);
// Free the allocated ODBC environment handle
SQLFreeEnv (hEnv);
return 0;
}
The program works but it doesn't get into the "if" section...
And what do I need to put in szDSN - just the database name or the whole connection string?
please help,
Thanks,
Eli
View 1 Replies
View Related
May 3, 2007
My application works with the Connection pooling ODBC. Everything works well, when it data base this down the SQLConnect function finishes steeply my application.
View 3 Replies
View Related
Mar 8, 2006
I have an
issue where SQL Server is refusing a connection that is initiated from
within a Windows service. The connection is attempted using the
SQLConnect ODBC function (yes I know there are newer and better things
out there but I'm stuck with ODBC for now ). SQLConnect returns
SQL_ERROR and the error code that is returned is:
28000
Invalid authorization specification
The value specified for the argument UserName or the value specified for the argument Authentication violated restrictions defined by the data source.
Now
it sounds like a username/password problem but when we attempt a
connection to the same server via a non-service program, everything
works fine (using the same username/password). We thought it might be
an ODBC issue at first but we can connect to a MySQL server using the
same programs/services just fine.
Checking the SQL Server setup, we do have both Windows accounts and SQL Server authentication enabled (under Security tab).
Anyone have any ideas?
thanks!
-Pete
View 10 Replies
View Related