S?a ch?a: Bo ng?i qu?n l? driver ODBC khng ng co SQL_NO_DATA_FOUND ANSI Driver

D?ch tiu ? D?ch tiu ?
ID c?a bi: 319243 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

Tri?u ch?ng

Khi b?n s? d?ng m?t tr?nh i?u khi?n ANSI ODBC, qu?n l? driver ODBC khng chnh xc c th? quay l?i SQL_NO_DATA_FOUND cho m?t c?t ?c ?nh ngh?a l VARCHAR ho?c CHAR v r?ng c m?t chu?i r?ng trong n. V?n ? x?y ra N?u cc c?t c ch?a m?t s? d? li?u ho?c m?t gi tr? "Khng". V?n ? ch? x?y ra n?u d? li?u l m?t chu?i r?ng v b?n gi?i h?n trn n t? pha khch hng v?i SQL_C_WCHAR.

Nguyn nhn

Qu?n l? driver ODBC sai gi? ?nh r?ng cc tr?nh i?u khi?n khng c b?t k? d? li?u khi n c? g?ng ? chuy?n ?i chu?i r?ng t? ANSI ? UNICODE.

Gi?i php

? gi?i quy?t v?n ? ny, c ?c cc m?i nh?t gi b?n ghi d?ch v? cho Microsoft SQL Server 2000. ? bi?t thm chi ti?t, b?m vo s? bi vi?t sau ? xem bi vi?t trong Microsoft Knowledge Cn c?:
290211 INF: Lm th? no ? c ?c SQL Server 2000 Service Pack m?i nh?t

Cch gi?i quy?t khc

M?t gi?i php n gi?n cho v?n ? ny l ? gi?i h?n trn cc c?t nh SQL_C_CHAR thay v? SQL_C_WCHAR.

T?nh tr?ng

Microsoft ? xc nh?n r?ng y l m?t v?n ? trong s?n ph?m c?a Microsoft ?c li?t k ? ?u bi vi?t ny. V?n ? ny l?n ?u tin ?c s?a ch?a trong Microsoft SQL Server 2000 Service Pack 3.

Thng tin thm

K? th?a cc ?ng d?ng s? d?ng m?t tr?nh i?u khi?n ANSI ODBC c th? khng g?p v?n ? ny, b?i v? h? c th? khng gi?i h?n trn cc c?t l SQL_C_WCHAR. B?i v? cc nh cung c?p ODBC Microsoft .NET g?n k t? ?i di?n c?t nh SQL_C_WCHAR theo m?c ?nh, b?n c th? g?p v?n ? ny n?u b?n s? d?ng Microsoft.net ODBC Nh cung c?p v?i m?t tr?nh i?u khi?n ANSI. Lu ? r?ng cc nh cung c?p ODBC Microsoft .NET tr? v? "NO_DATA" khi v?n ? ny x?y ra.

Cc b?c ? sao chp cc hnh vi

M?u b?n ?a sau ch?ng t? v?n ?:
  1. S? d?ng k?ch b?n sau y ? t?o ra m?t b?ng v a ?a H? s:
    Create Table Test (ID integer, COL1 CHAR(10))
    Insert Into Test VALUES (1,'')
    					
  2. Ch?y chng tr?nh C sau y:
    #include <windows.h>
    #include <stdio.h>
    #include <sql.h>
    #include <sqlext.h>
    
    int main(int argc, char* argv[])
    {
    	SQLCHAR*	theDiagState = new SQLCHAR[50];
    	SQLINTEGER	theNativeState;
    	SQLCHAR*	theMessageText  = new SQLCHAR[255];
    	SQLSMALLINT	iOutputNo;
    	SQLHENV		m_SQLEnvironment;
    	SQLHDBC		m_SQLConnection;
    	SQLHSTMT	m_SQLStatement;
    	SQLRETURN	iReturn;
    	long		lStrLen;
    	char		theData[1000];
    
    	//Connect.
    	iReturn = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&m_SQLEnvironment);
    	iReturn = SQLSetEnvAttr(m_SQLEnvironment,SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3,0);
    	iReturn = SQLAllocHandle(SQL_HANDLE_DBC,m_SQLEnvironment,&m_SQLConnection);
    
    	//CHANGE THE DSN NAME HERE.
    	char	szConnBuffer[1024];
    	short   cbOutConn;
    	char    szConnStr[255];
    
             strcpy(szConnStr,"DSN=YourANSIDSN;UID=YorUid;Pwd=YourPassword");
    	
    	iReturn= SQLDriverConnect(m_SQLConnection, NULL,
    (SQLTCHAR*) szConnStr,strlen(szConnStr), 
    (SQLCHAR*) szConnBuffer,1024, &cbOutConn, SQL_DRIVER_NOPROMPT);
    
    	if (iReturn != SQL_SUCCESS)
    	{
    		SQLGetDiagRec(SQL_HANDLE_DBC,m_SQLConnection,1,theDiagState,
    &theNativeState,theMessageText,100,&iOutputNo);
    	}
    
    	//Run query.
    	iReturn = SQLAllocHandle(SQL_HANDLE_STMT,m_SQLConnection,&m_SQLStatement);
    
    	//The Test table contains COL1 column which is set to empty for the first record.
    
    	iReturn = SQLExecDirect(m_SQLStatement, (SQLCHAR*) "Select ID,COL1 FROM Test",SQL_NTS);
    	iReturn = SQLFetch(m_SQLStatement);
    
    	iReturn = SQLGetData(m_SQLStatement,2,SQL_C_WCHAR,theData,100,&lStrLen);
    
    	//The problem does not occur if you bind the same column to SQL_C_CHAR.
    	//iReturn = SQLGetData(m_SQLStatement,2,SQL_C_CHAR,theData,100,&lStrLen);
    
    	if (iReturn != SQL_SUCCESS)
    	{
    		//iReturn will be 100 SQL_NO_DATA_FOUND here with NO other message.
    		int CheckHere;
    		CheckHere = 0;  //It will come here.
    		if (iReturn == SQL_NO_DATA_FOUND)
    		{
    			printf("SQL_NO_DATA_FOUND has been returned.\n Press Enter key to continue...\n");
    			getchar();
    		}
    		
    	}
    
    	//DISCONNECT.
    	iReturn = SQLFreeHandle(SQL_HANDLE_STMT,m_SQLStatement);
    	iReturn = SQLDisconnect(m_SQLConnection);
    	iReturn = SQLFreeHandle(SQL_HANDLE_DBC,m_SQLConnection);
    	iReturn = SQLFreeHandle(SQL_HANDLE_ENV,m_SQLEnvironment);
    
    	m_SQLStatement = NULL;
    	m_SQLConnection = NULL;
    	m_SQLEnvironment = NULL;
    
    	delete theMessageText; 
    	delete theDiagState;
    
    	return 1;
    }
    					
    B?n nh?n ?c thng bo sau:
    SQL_NO_DATA_FOUND ? ?c tr? l?i.
    B?m phm Enter ? ti?p t?c...

Thu?c tnh

ID c?a bi: 319243 - L?n xem xt sau cng: 28 Thang Sau 2013 - Xem xt l?i: 3.0
p d?ng
  • Microsoft Data Access Components 2.7
T? kha:
kbhotfixserver kbqfe kbdownload kbsqlserv2000sp3fix kbbug kbfix kbsqlserv2000presp3fix kbmt KB319243 KbMtvi
My d?ch
QUAN TRONG: Bai vit nay c d?ch b?ng phn mm dich thu?t cua Microsoft va co th c Cng ng Microsoft chinh sa l?i thng qua cng ngh CTF thay vi mt bin dich vin chuyn nghip. Microsoft cung c?p cc bi vi?t ?c c? bin d?ch vin v ph?n m?m d?ch thu?t th?c hi?n v c?ng ?ng ch?nh s?a l?i ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng nhi?u ngn ng? Tuy nhin, bi vi?t do my d?ch hoc thm chi cng ng chinh sa sau khng ph?i lc no c?ng hon h?o. Cc bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny: 319243

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com