Quantcast
Channel: SQL Server Data Access forum
Viewing all 4164 articles
Browse latest View live

JDBC: PreparedStatement.getParameterMetaData() does not work when the SQL contains embedded newlines

$
0
0

Consider the following table

create table foo 
(
    id integer not null primary key, 
    some_data varchar(100)
);

Now the following Java Code:

PreparedStatement pstmt = connection.prepareStatement("select * \nfrom foo \nwhere id = ?");
ParameterMetaData meta = pstmt.getParameterMetaData();

will throw an Exception:

com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: Unable to identify the table select *
from foo
where id = ? for the metadata.
 at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
 at com.microsoft.sqlserver.jdbc.SQLServerParameterMetaData.<init>(SQLServerParameterMetaData.java:426)
 at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.getParameterMetaData(SQLServerPreparedStatement.java:1532)

When the embedded newlines are removed from the SQL, the call works.

The driver version is: 4.0.2206.100
SQL Server Version is: 11.00.2100
Java Version is: 1.6.0_31
Windows 7 64bit


Execution plan for ITVF called by Stored Procedure

$
0
0

Hello Forum,

I'm a developer that's new to the world of SQL Server, having come from using Oracle as the RDBMS for the past decade.
My question is regarding finding execution plans for inline table-valued functions called from stored procedures.

The scenario is the following ... SP1 (stored procedure 1) returns two result sets, both of which query ITVF1 (inline table-valued function 1).  SP1 is called from a Python module, using PyODBC.  When running the SQL Server Profiler, I can see that PyODBC is using prepared statements for calling SP1.  What I would like to do is to use the SQL Server Profiler to capture the execution plan that ITVF1 uses when it is called by SP1.  So far, I have not found a way to do that.  Is it possible?

I looked through the plan cache and also did not find any trace of the execution plan I'm looking for.  Here's the query I used for looking through the plan cache:

SELECT UseCounts, Cacheobjtype, Objtype, TEXT, query_plan
FROM sys.dm_exec_cached_plans 
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
CROSS APPLY sys.dm_exec_query_plan(plan_handle)
WHERE TEXT like '%SecMasterSearch%'

Is SQL Server capturing the execution plan for ITVF1 somwhere in this scenario?  Or is it lost since ITVF1 is two levels deep in the call chain (i.e. called indirectly from a prepared statement by way of SP1)

Let me know if I have not provided sufficient background information.

Thanks, in advance, for any tips.

K


ODBC Data Source Administrator (64-bit) crashes when I invoke PostgreSQL ANSI(x64) or Unicode(x64) drivers

$
0
0

ODBC Data Source Administrator (64-bit) crashes with the following operation:

1. Open 'ODBC Data Source Administrator (64-bit).
2. Choose 'User DSN' tab
3. Click 'Add' on right of windows. 'Create New Data Source' window opens
4. Select driver 'PostgreSQL ANSI(x64)'
5. Click 'Finish'
6. Then get message 'ODBC Administrator has stopped working', with only option 'Close program'. A generic, unhelpful message is give: "A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available."

Using the 32 bit ODBC Data Source Administrator and 32 bit driver there is no problem. I also had no problem with this under Windows 7 using the 64 bit drivers. What might cause this? Is there a way to debug and determine whether the driver is at fault or whether it's ODBC Data Source Administrator.

Further information:

This Windows 8 Enterprise 64 bit installation was an upgrade from Windows 7 Enterprise 64 bit.

The PostgreSQL ANSI(x64) driver can be installed from: http://www.postgresql.org/ftp/odbc/versions/msi/

I am using version 'psqlodbc_09_01_0200-x64'

Please request any further information that might be useful.

Regards,
Tom.

NB Reposted from Windows 8 IT Pro Forums: http://social.technet.microsoft.com/Forums/en-US/w8itprogeneral/thread/4cea8098-fa08-489f-99ca-ee3ab5592dc0/

Getting top value for each group of line number in sql server 2000

$
0
0

My code:

SELECT  t1.LINE_NO, t1.HSA_STATUS, t1.FAMILY, t1.CACHE_FAMILY, 
    SUM(t1.TOTAL) AS CountOfLineNo, t2.TotalOfLineNo, 
    convert(decimal(18,3),(convert(decimal(8,1),SUM(t1.TOTAL)) * 100 / t2.TotalOfLineNo )/100)AS Percentage
    FROM (
          SELECT LINE_NO, E_FIELD,F_FIELD,G_FIELD,HSA_STATUS,FAMILY,CACHE_FAMILY, Count(LINE_NO) as Total
          FROM TX_HSA_SUMM
          WHERE MT_TIMESTAMP2 BETWEEN ('2013-03-07 10:10:00') AND ('2013-03-08 10:20:00')
          AND  E_FIELD!='00000' AND F_FIELD!='00000' AND G_FIELD!='00000' -- added new line
          GROUP BY LINE_NO,E_FIELD,F_FIELD,G_FIELD,HSA_STATUS,FAMILY,CACHE_FAMILY
        ) AS t1 
    LEFT JOIN (
          SELECT LINE_NO, COUNT(LINE_NO) AS TotalOfLineNo
          FROM TX_HSA_SUMM
          WHERE MT_TIMESTAMP2 BETWEEN ('2013-03-07 10:10:00') AND ('2013-03-08 10:20:00')
           --AND  E_FIELD!='00000' AND F_FIELD!='00000' AND G_FIELD!='00000' -- added new line 
          GROUP BY LINE_NO 
          ) AS t2 
    ON t1.LINE_NO = t2.LINE_NO    
GROUP BY t1.LINE_NO, t1.E_FIELD, t1.F_FIELD, t1.G_FIELD, t1.HSA_STATUS, t1.FAMILY, t1.CACHE_FAMILY, t1.Total,t2.TotalOfLineNo
--HAVING convert(decimal(18,3),(convert(decimal(8,1),SUM(t1.TOTAL)) * 100 / t2.TotalOfLineNo )/100) > '0.3' 
HAVING t2.TotalOfLineNo > '500'
ORDER BY t1.LINE_NO, t1.E_FIELD, t1.F_FIELD, t1.G_FIELD, t1.HSA_STATUS, t1.FAMILY, t1.CACHE_FAMILY, t1.Total,t2.TotalOfLineNo     

 The above is my code. I need to get the highest value in each group to do some calculation. 

Sample data is 

LINE_NOHSA_STATUS FAMILYCACHE_FAMILY CountOfLineNo TotalOfLineNo Percentage
23059BS                SUMMIT    WER                  1               526          0.002
23059BS                SUMMIT    WER                  3                526           0.006
23059BS                SUMMIT   WER                  2               526          0.004
23059BS                SUMMIT   WER                  1              526          0.002
23059BS                 SUMMIT   WER                  3             526          0.006

---------------------------------------------------------

64006MP                 SUMMIT   WER                  2             2838          0.001
64006MW                SUMMIT   WER                 6            2838          0.002
64006MP                SUMMIT   WER                 3 2838          0.001

As you can see two different group of rows, I need to get the highest value for each row should be display at the top of each row group as shown below:

LINE_NOHSA_STATUSFAMILYCACHE_FAMILYCountOfLineNo TotalOfLineNo Percentage

23059BS                 SUMMIT   WER                  3             526          0.006

23059BS                SUMMIT    WER                  1               526          0.002

23059BS                SUMMIT   WER                  2 526          0.004
23059BS                SUMMIT   WER                  1              526          0.002

---------------------------------------------------------

64006MW                SUMMIT   WER                 6            2838          0.002

64006MP                 SUMMIT   WER                  2 2838          0.001

64006MP                SUMMIT   WER                 3           2838          0.001

it should display in this order so that it will easy for me to do the calculation. Thanks in advance.


Sql Server 2012 Connection error "ADODB.Connection error '800a0e7a' "

$
0
0
Hey guys....can someone help me please
i'm running an asp application on a windows 7 home premium (64 bit)
and i keep getting this error over and over ADODB.Connection error '800a0e7a' Provider cannot be found. It may not be properly installed. (line 68)

here is the code :

dim fname, lname, minitial, email, phone, dob, grade
dim CardNumber, PWord, reminder, fullname, fixm
dim ActiveP, Resident, FriendsExp, prob, holdcard
dim fnx, lnx, mnx, rs, pIndex, Fdate, DobDate
dim adding
dim fdatedata, dobdatedata
dim Name, City, State, Contacted, lastEmailed, SecondToLastEmailed, Comments
dim MuseumPasses, Title



pIndex = Request.Form("pIndex")
contacted = Request.Form("iActive")
MuseumPasses = Request.Form("iResident")
LastEmailed = Request.Form("iFriendsExDate")
name = Request.Form("iTitle")
email = Request.Form("iEmail")
SecondToLastEmailed = Request.Form("iDOB")
Comments = Request.Form("iCardNumber")
City = Request.Form("iPassword")
State = Request.Form("iReminder")
adding = request.form ("adding")

Title = Request.Form ("Title")
prob = name
prob = Replace(prob, " ", " ")
holdcard = request.form("holdcard")

if NOT IsValidEmail(email) Then
response.write "Bad Email Address, not updated"
response.end
end if




if len(state) > 2 then

state = left(state,2)
end if
if request.form("Submit") = "Delete Prospect Information" then
response.write "<center><FORM Action='mlremove.asp' Method='POST' Name='ATA'>"
response.write "Are you sure you want to delete: " & name & " " & email & "?"
response.write "<P><input type='submit' name='yes' value='yes'>&nbsp;&nbsp;&nbsp;"
response.write "<input type='submit' name='no' value='no'>"
response.write "<input type='hidden' name='indexer' value=" & pIndex & ">"
Response.write "</form></center>"
response.end
end if

if MuseumPasses = 1 then
MuseumPasses = myTrue
else
MuseumPasses = myFalse
end if

if Contacted = 1 then
Contacted = myTrue
else
Contacted = myFalse
end if

set dbconn = Server.CreateObject("ADODB.Connection")
dbconn.ConnectionString = strConn
dbconn.Open (thats the line where i get the error)



IF request.Form("update") <> "update" then

set rs = Server.CreateObject("ADODB.recordset")
rs.CursorLocation = 3
sql = "SELECT name, email FROM MailList WHERE email = '" & email & "';"
rs.open sql, dbconn
if rs.RecordCount <> 0 then
fnx = rs("name")
rs.close
set rs = nothing
dbconn.close
set dbconn = nothing
response.redirect "mlAdd.asp?bd=6&per=" & escape(prob) & "&cn=" & email
end if
rs.close
set rs = nothing
sql=""


the connection string that im using to connect to my Microsot Sql Server 2012 database is the following :

strConn="Provider=SQLNCLI;Server=*****;Database=** ***;Trusted_Connection=yes;"


So i was thinking probably the provider is not correct ?
I need help guysssssssssssssss pleaseeeeeeeeeeeee thats an end of study project for my school

Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2260.0' : file not found

$
0
0

One process fails with this ODBC error message:
Can't open lib '/opt/microsoft/msodbcsql/lib64/libmsodbcsql-11.0.so.2260.0' : file not found
Even though the file is clearly there.

Another process (a smaller executable, from the command line) succeeds.

The straces of a succeeding and failing process are on

https://skydrive.live.com/?cid=7351CCB20D6E0D6A&id=7351CCB20D6E0D6A%21103

File: succeeds_and_fails.zip

Why does the connect fail in one case but succeed in another?

How to compare values from datatable

$
0
0
Hi my code is
 
If LineNo = Family Then
If FailCount >= 500 Then 'This is for the sum of that line 
'Get the highest percentage by taking Count(*) / total count * 100
For Each Row As DataRow In tblRawTesterShutdown.Rows
With objShutdownReport
.ShutdownType = _ShutdownType
.TesterID = LineNo
.QuadID = "0"
.E_Code = Row.Item("E_FIELD").ToString.Trim
.F_Code = Row("F_FIELD").ToString.Trim
.G_Code = Row("G_FIELD").ToString.Trim
.Status = Row("HSA_STATUS").ToString.Trim
.Family = Row("FAMILY").ToString.Trim
.Count = CInt(Row.Item("TOTAL"))
.StartTime = StartTime
.Timestamp = NowTime
.CACHE_FAMILY = Row.Item("CACHE_FAMILY").ToString.Trim
 
If Percentage = Then <--- At this part it will get percentage value actually, so here it should find the top value and minus the second value. Anywan can help how to do the looping here. sample data is shown below.

Else

End If
End With
Next
Else
MsgBox("No shutdown")
End If
End If 'end here

 
This is my code. I need an help actually to get the top percentage from particular row number and minus the second top of percentage. I quite confuse with the logic. So for an example the first percentage is 0.006 should minus with 0.004 since it should ignore 0.001. With the difference then it should minus again with 0.004 to find the difference. Pls help me. Thanks in advance.
 
LINE_NO E_FIELD F_FIELD G_FIELD FAMILY HSA_STATUS CACHE_FAMILYCountOfLineNo TotalOfLineNo %
23059B 00353 00418 00684 SUMMIT S WER 3 526 0.006
64006M 00353 00418 00684 SUMMIT R WER 2 2838 0.001
23059B 00353 00418 00758 SUMMIT S WER 2 526 0.004

"A network-related or instance-specific error occurred while establishing a connection to SQL Server" for the projets who execute the query sql

$
0
0

Hello All,

Since the last week, i found a problem that nearly all the projets (asp.net and workflow for dynamics CRM 4) doesnt work, they have the same message "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) ", and also error 40 displayed in certain web application.

I have checked the related article on the net and i dont think it is the problome about the connection string and configuration of sql server, because the sql server can be connected via sql management studio.
what's more, i have debug one of them (projet asp.net) in  visual studio and it works but when i complied this projet and deployed this on the IIS(the web.config is OK), it still has the error massage as show before.
And then i think maybe it is the problome of IIS, but the strand things is that there is another projet asp.net who user the same website and application pool as the other projets asp.net, sometimes it works and sometimes not.
I also verfied the registe (oledbtimeout and extension timeout) of the CRM server and the trace logs of CRM, but i cant find the solution.

Thanks so much if anyone can give me some ideas.


reading windbg stack trace

$
0
0

I had an access violation error which caused the sql server services to shut down. I used windbg to debug the sql dump and got the below stack trace.

to me it seems that msxml is a problem and prepared xml procedures are being used to process xml file causing issues.

can some check and verify whether I am correct or not?

This is on sql server 2008 r2 standard RTM edition.

0:000> KC 100
Call Site
KERNELBASE!RaiseException
sqlservr!CDmpDump::Dump
sqlservr!SQLDumperLibraryInvoke
sqlservr!CImageHelper::DoMiniDump
sqlservr!stackTrace
sqlservr!stackTraceCallBack
sqlservr!ex_handle_except
kernel32!UnhandledExceptionFilter
ntdll! ?? ::FNODOBFM::`string'
ntdll!_C_specific_handler
ntdll!RtlpExecuteHandlerForException
ntdll!RtlDispatchException
ntdll!KiUserExceptionDispatcher
msxml6!Base::freeRentalObjects
msxml6!Base::StackExitNormal
msxml6!ModelInit::~ModelInit
msxml6!SAXReader::parse
MSO
0x0
0x0
0x0

Cheers!!! SqlFrenzy

Connectivity to Oracle database from workstation running 2008 management studio failing

$
0
0

I installed Oracle 11GR2 client on a MSSQL 2008 server that needed to read tables on an Oracle 11G database. Set up the linked server using OraOLEDB.Oracle, put in user credentials and all is good, now the user in MSSQL can see the tables.

A developer wants to access the MSSQL database from his workstation, and when connecting to the above database through 2008 Management Studio he could not see the external tables.  Being more familiar with Oracle than MSSQL I didn't think he'd need the Oracle client on his workstation, but it appears he does, so we installed the Oracle client on the workstation but are still not able to see the external tables. I made sure the Oracle install was in his path and was able to tnsping the Oracle database we're connecting to so I know that is ok. 

 We are getting a Msg 7302: Cannot create an instance of OLE DB provider "OraOLEDB.Oracle" for linked server "<oracledb>"

Just to test further, we tried creating the linked server from his local MSSQL database and it let us create the link, but gets a different error when trying to see linked tables. He's away for now and I can't recall that error, but the main one I am concerned about is when trying to connect through the database server. 

Any ideas? 

I am curious too, why does MSSQL need the Oracle client on a workstation connecting to an external MSSQL database through Management Studio?  

ps. I also have 2008 management studio on my workstation, as well as several Oracle installs, I am able to see connected tables on MSSQL database with no issues. 

SQL OpenDataSource using ACE.OLEDB.12.0

$
0
0

Hi,

 

I was able to set this up successfully on my local and on production, as long as  the user credentials used on running the script is a sysad.

It's been up and running for months already. And just all of a sudden, sometime around last week, I received a complaint from one of our users who utilizes the uploader that they can no longer upload any excel files.

 

OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Unspecified error". Msg 7303, Level 16, State 1, Line 1 Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server"(null)".

 

No one is altering the script. 

No one has updated the server nor my local. 

All of the servers for different apps that uses the script encoutered the error.

I can't even run it on my own local pc.(When I use JET as a driver on my local it still works, but can't run it using ACE driver) 

 

I'm really confused already on what happened on the ace driver? 

I'm starting to wonder if there have been any update backend from microsoft or some kind of a bug on the ace driver??

 

Hope someone could help me if you have similar issue.

 

 

Thanks,

 

The DBComms.receive operation resulted in an invalid packet header type:-86 PktNum:0 nReceived :8

$
0
0

I am getting this below errors occasionally .  Could any one suggest on this how to resolve this kind of issues and what might be the root causes for this error

Error as below

----------------------

TestTag:doEndTag(),0,The DBComms.receive operation resulted in an invalid packet header type:-86.  PktNum:0.  nReceived:8.
**16-mrt-2013 9:59:16,JSP Runtime Error,0,javax.servlet.jsp.JspException: The DBComms.receive operation resulted in an invalid packet header type:-86.  PktNum:0.  nReceived:8.
at com.test.tagSupport.TestTag.doEndTag(TestTag.java:39)..

awaiting for the responses. quick response will be appreciated.

-thank you.....

At most one record can be returned by this subquery

$
0
0

I am using C# with an Access database and the following query:

msSQL = "SELECT * FROM myTable WHERE ";
. . .
msSQL += "contactLocationID = (SELECT DISTINCT location.locationID FROM location INNER JOIN client ON location.locationClientID = client.clientID " +"WHERE (((client.clientName) LIKE '%" + txtClientName.Text + "%'))) ";

... but it gives me an error message saying, "At most one record can be returned by this subquery".  I built the query with the designer in the Access database and it works there.

REvans

Network related or instance specific error

$
0
0

Hi,

I can use ip address and port no in connection string to connect to a named-instance.

I can connect with the following connection string:

"Data Source=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;
User ID=myUsername;Password=myPassword;"

I cant connect to the instance by specifying instance name.

How do I do it?

Also I cant browse for the instance in SSMS.

Thanks

SQL to Oracle linked server throws errors

$
0
0
We have linked server from SQL server 2000 instance to Oracle server. Linked server has been working fine for last 3 years and suddenly it has started throwing errors.
 
When we run simple select statement on query analyzer (SELECT * FROM KDBPRD...GROUP MASTER) it throws different errors and brings back different row count every time we run this.  
 
Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'MSDASQL' reported an error.   
[OLE/DB provider returned message: [Oracle][ODBC][Rdb]  send() Ret -1 Err#10038 WSAENOTSOCK File descriptor not a socket]
OLE DB error trace [OLE/DB Provider 'MSDASQL' IOpenRowset::OpenRowset returned 0x80004005:   ].
 
SERVER: MSG 7399, LEVEL 16, STATE 1,  
OLE DB PROVIDER 'MSDASQL' REPORTED AN ERROR.   
[OLE/DB PROVIDER RETURNED MESSAGE: [ORACLE][ODBC][RDB]%SQLSRV-F-FATALEXECERR, FATAL EXECUTOR PROCESS ERROR]
OLE DB ERROR TRACE [OLE/DB PROVIDER 'MSDASQL' IROWSET::GETNEXTROWS RETURNED 0X80004005:   ].
 
 
OLE DB PROVIDER "MSDASQL" FOR LINKED SERVER "KDBPRD" RETURNED MESSAGE "[ORACLE][ODBC][RDB]%SQLSRV-F-FATALEXECERR, FATAL EXECUTOR PROCESS ERROR".
MSG 7330, LEVEL 16, STATE 2, LINE 1
CANNOT FETCH A ROW FROM OLE DB PROVIDER "MSDASQL" FOR LINKED SERVER "KDBPRD".
 
Select TOP 100 gets completed successfully periodically and throws errors. Has anyone seen this kind of behavior?


Database unaccessible -- solution was to take offline and bring back online. Why did this happen?

$
0
0

I'm a Jr. DBA at a software company that offers hosting solutions to our customers.  Yesterday we had an incident where a database used by one of our products became inaccesible.  In SSMS we could see the database listed but were unable to expand the contens of the database in Object Viewer.  I was not here at the time but I was informed later the solution was to bring it offline and then back online.

I'm doing a post-mortem report on the incident and have been unable to find anything useful in determining why this happened.  I see nothing in SQL or Windows logs other than this error reported in the server's application log:

"The following information is part of the event: <domain omitted>\<username omitted>,  Reason: Failed to open the explicitly specified database"

Reviewing the Data portion of the event noted that the database that was attempted to be accessed was the master database.  What's interesting is this is NOT the database that was having the issue.  Additionally, I checked and the default database of this account is the master database, but I did verify this account does have access to the master database and I also noted this member of the sysadmin server group.

Finally, I reviewed the default SQL trace to see if I could find anything additional reported there but was unable to find anything of use outside of the failed attempts to access the master database already noted in the application log.

 

Is there anything else I can do or anywhere else I can look to better understand what happened and why bringing the database offline/online fixed the issue?  I appreciate any and all assistance!

 

Multiple SQL_HANDLE_DBC handles do not work on Linux

$
0
0

Hello,

I am seeing the following error from the SQL Server Driver For Linux when I attempt to execute a query on a SECOND connection within my application:

SQLSTATE: IM001
Native Error Code: 0
Message: [unixODBC][Driver Manager]Driver does not support this function

I have compiled/run the test case I have on Windows and the code executes without issue.

Here is my test case:

// SQLGetData.cpp
//
// g++ -M64 -I$ODBC/include -L$ODBC/lib -g -lodbc sqlgetdata.cpp
// cl sqlgetdata2.cpp odbc32.lib
//
// CREATE TABLE tstDFRBLB(col1 varbinary(max))

#if defined(_WIN32)
#include <windows.h>
#endif

#include <stdlib.h>
#include <stdio.h>

#include <sql.h>
#include <sqlext.h>

void checkError ( SQLRETURN rc, const char *cstr )
{
    if( rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO ) {
        return ;
    } else if( rc == SQL_INVALID_HANDLE ) {
        fprintf( stderr, "Error: invalid handle: %s.\n", cstr ) ;
    } else {
        fprintf( stderr, "Unknown Error occured in %s: code %d.\n", cstr, rc ) ;
    }
}

void checkStmtError( SQLRETURN rc, SQLHSTMT stmth )
{ 
    if(rc != SQL_SUCCESS) {
        int i = 1 ;
        SQLSMALLINT length;
        
        SQLINTEGER sqlcode;
        SQLCHAR *sqlstate = (SQLCHAR *) malloc(100  * sizeof(SQLCHAR));
        SQLCHAR *message  = (SQLCHAR *) malloc(1000 * sizeof(SQLCHAR));
        
        while ( SQLGetDiagRec( SQL_HANDLE_STMT, stmth, i, sqlstate, &sqlcode, 
                   message, 1000, &length ) == SQL_SUCCESS ) {
           printf( "\nSQLSTATE: %s\n", sqlstate ) ;
           printf( "Native Error Code: %ld\n", sqlcode ) ;
           printf( "Message: %s\n", message ) ;
           i++ ;
        }
       delete sqlstate;
       delete message;
    }
}

int main( int ac, char **av )
{
    SQLHENV    envh ;
    SQLHDBC    dbch ;
    SQLHDBC    dbch2 ;

    SQLRETURN    rc ;
    SQLHSTMT    stmth ;

    const char    *select_stmt = "SELECT * FROM tstDFRBLB" ;
    /* Allocate a environment handl */
    rc = SQLAllocHandle( SQL_HANDLE_ENV,    // Handle type
             SQL_NULL_HANDLE,    &envh            // SQLHENV handle (environment)
               ) ; 
    checkError( rc, "SQLAllocHandle - SQL_HANDLE_ENV" ) ;


    /* Set environment attributes */
    rc = SQLSetEnvAttr( envh,         // Environment handle
            SQL_ATTR_ODBC_VERSION,    // Attribute to set
            (SQLPOINTER) SQL_OV_ODBC3,// New attribute
            SQL_NTS                   // SQL_NTS (null terminated)
         ) ;
    checkError( rc, "SQLSetEnvAttr" ) ;

    /* Allocate a database connection handle */
    rc = SQLAllocHandle( SQL_HANDLE_DBC,    // Handle Type
             envh,            // Where to attatch the new handle
             &dbch            // Pointer to new handle
               ) ;
    checkError( rc, "SQLAllocHandle - SQL_HANDLE_DBC" ) ;

    /* Establish a connection */
    SQLCHAR outStr[1024];
    SQLSMALLINT outSize;
    rc = SQLDriverConnect(dbch, NULL,
#if defined(_WIN32)
                      (SQLCHAR*)"DSN=MSSQL_2012_NC_64;UID=*****;PWD=*****;DATABASE=qe1;", 57,
#else
                      (SQLCHAR*)"DSN=mssql-2012-md_64;UID=*****;PWD=*****;DATABASE=qe1;", 57,
#endif
                      outStr, sizeof(outStr), &outSize, SQL_DRIVER_NOPROMPT);    
   /* Allocate a second database connection handle */
    rc = SQLAllocHandle( SQL_HANDLE_DBC,    // Handle Type
             envh,            // Where to attatch the new handle&dbch2            // Pointer to new handle
               ) ;
    checkError( rc, "SQLAllocHandle - SQL_HANDLE_DBC" ) ;

    rc = SQLSetConnectAttr(dbch2,
            SQL_ODBC_CURSORS,
            (SQLPOINTER)SQL_CUR_USE_DRIVER,
            (SQLINTEGER)NULL); // this value is ignored
    checkError( rc, "SQLSetConnectAttr - SQL_ODBC_CURSORS" ) ;

    rc = SQLDriverConnect(dbch2, NULL,
#if defined(_WIN32)
                      (SQLCHAR*)"DSN=MSSQL_2012_NC_64;UID=*****;PWD=*****;DATABASE=qe1;", 57,
#else
                      (SQLCHAR*)"DSN=mssql-2012-md_64;UID=*****;PWD=*****;DATABASE=qe1;", 57,
#endif
                      outStr, sizeof(outStr), &outSize, SQL_DRIVER_NOPROMPT);    
    rc = SQLAllocHandle( SQL_HANDLE_STMT, dbch2, &stmth ) ;
    checkError( rc, "SQLAllocHandle - SQL_HANDLE_STMT" ) ;

    /*
    ** Read the value back
    */
    rc = SQLExecDirect( stmth, (SQLCHAR*)select_stmt, SQL_NTS ) ;
    checkStmtError( rc, stmth );

    char outWData[168000];
    SQLLEN  outInd = 0;
    while ( SQLFetch( stmth ) == SQL_SUCCESS )
    {
        rc = SQLGetData( stmth, 1, SQL_C_BINARY, outWData, sizeof(outWData), &outInd );
        checkStmtError( rc, stmth );
        if(outInd == SQL_NULL_DATA) {
            printf("Data Returned: NULL\n");
        }
        else {
            printf("Data Returned Length %d\n", outInd);
        }

        rc = SQLMoreResults(stmth);
        checkStmtError( rc, stmth );
    }


    /* Disconnect from the database */
    rc = SQLDisconnect( dbch2 ) ;
    checkError( rc, "SQLDisconnect" ) ;

    /* Free connection and environment handles */
    rc = SQLFreeHandle( SQL_HANDLE_DBC, dbch2 ) ;
    checkError( rc, "SQLDisconnect" ) ;

    /* Disconnect from the database */
    rc = SQLDisconnect( dbch ) ;
    checkError( rc, "SQLDisconnect" ) ;

    /* Free connection and environment handles */
    rc = SQLFreeHandle( SQL_HANDLE_DBC, dbch ) ;
    checkError( rc, "SQLDisconnect" ) ;

    SQLFreeHandle( SQL_HANDLE_ENV, envh ) ;
    checkError( rc, "SQLDisconnect" ) ;

    return EXIT_SUCCESS ;
}

Thank you for any help/advice.

Dave


David Ritter

how & what SQL do I upgrade to on windows 8 so that ACT 2009 will work

$
0
0
how & what SQL do I upgrade to on windows 8 so that ACT 2009 will work

How to use user's settings on a quiz?

$
0
0

Hi guys,

I have a database named Quiz and 2 tables in it, one Questions with the following fields: ""questionID", "description", "difficulty" , "chapter" and the other table namedSettings with 5 fields : "settingsID", "difficulty", "chapter", "random", "number_of_questions". Now, that i want is the following...! I have made a DetailsView with theSettings table bind on it and have "checked" the option "generate insert,delete and update statements" so the user can insert his own settings for the quiz(this works). I want to show the questions that depend on the user's settings. I mean that, if the user inserts new settings with values 1,3,true,15 (difficulty,chapter,random,number_of_questions), the quiz should automatically show 15 questions with difficulty =1, from chapter=3 and to be in random order.

i would appreciate it if you can help me

Thanks

Pantelis G.

Is it possible to specify a non-"logged in" domain user via a VB6 ADO connection string with SSPI authentication?

$
0
0

I have several old VB6 applications that connect to the database using SQL Logins. The database is being upgraded and moved to a new location which requires Windows Authentication and does not allow mixed-mode or SQL Login authentication. I have read about"impersonation" for my web apps in IIS. Is there any way to specify a domain user account for the ADO connection to the database instead of the "logged in" user? Everything I can find online so far indicates that when you set Integrated Security=SSPI in the connection string the User ID and password keywords become meaningless. This behavior seems appropriate to me for Windows Authentication, but I keep getting told by the architect of the relocated database server that my application CAN control what user is authenticated to the database via the connection string (unfortunately no examples are provided.)

Thanks for any input!

Viewing all 4164 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>