question

tapas avatar image
tapas asked

How To open a ReadOnly Intent Connections using Microsofts Linux ODBC Driver

Hi, I was trying to connected to a alwaysOn cluster's secondary server. This server only accepts readIntent Connections. The problem is, even after specifying the ApplicationIntent property in the Connection String, I am not able to connect to it. From the JDBC driver, I am able to open the connection. Also while specifying the driver version to the latest 3.80, the code stops working. Following is the small snippet from the code char *ConnectionString = "Driver=SQL Server Native Client 11.0;Server=xx.xx.xx.xx;Port=1433;Database=db***;UID=sa;PWD=*******;ApplicationIntent=ReadOnly;"; char ConnStrOut [200]; SQLSMALLINT cbConnStrOut; // Allocate environment handle retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); // Set the ODBC version environment attribute if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { printf("\nMain Started\n"); retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3_80, 0); // Allocate connection handle if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { printf("Trying To Allocate Handle......\n"); retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); // Set login timeout to 5 seconds if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { printf("Handle Allocated...\n"); SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)10, 0); //SQLSetConnectAttr(hdbc, SQL_COPT_SS_APPLICATION_INTENT, TEXT("Readonly"), SQL_NTS); // Connect to data source printf("Trying To Connect to %s\n",ConnectionString); //retcode = SQLConnect(hdbc, (SQLCHAR*) "SQLCMD", SQL_NTS, (SQLCHAR*) "Test1", 5, (SQLCHAR*) "Password1", 9); retcode = SQLDriverConnect(hdbc, NULL, (SQLCHAR *)ConnectionString, strlen(ConnectionString), (SQLCHAR *)ConnStrOut, sizeof(ConnStrOut), &cbConnStrOut, SQL_DRIVER_NOPROMPT); // Allocate statement handle if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) { printf("Connected Sucessfully...\n"); retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); Microsofts's website show that this property is supported in the latest driver. As you can see from the code, I have even tried SQLSetConnectAttr to do the same. http://msdn.microsoft.com/en-US/library/ms131310.aspx
odbclinux
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.