“字符串数据,右截断";选择语句警告 [英] "String data, right truncation" warning on a select statement

查看:717
本文介绍了“字符串数据,右截断";选择语句警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Access 2003数据库升级到SQL Server Express2008.表似乎已创建好,数据看起来也很好.

I am upscaling an access 2003 database to SQL Server Express 2008. The tables appear to be created ok and the data looks ok.

我有一个连接到该数据库的MFC应用程序.连接访问可以正常工作,但是当我连接到SQL Server时,在select语句上收到以下错误.

I have an MFC application that connects to this database. It worked fine connecting to access, but when I connect to SQL Server I am getting the following error on a select statement.

DBMS: Microsoft SQL Server
Version: 10.50.1600
ODBC Driver Manager Version: 03.80.0000
Warning: ODBC Success With Info on field 0.
String data, right truncation

State:01004,Native:0,Origin:[Microsoft][ODBC SQL Server Driver]

返回的数据应为8个字符,但只有7个字符,最右边的字符被截断.

The data that is returned should be 8 characters but is only 7 with the right most character truncated.

访问前端可以从SQL Server正确读取数据.

The access front end can read the data from SQL Server correctly.

SQL Server表中的字段定义为长度为8的nvarchar.

The field in the SQL Server table is defined as nvarchar with a length of 8.

读取字段的代码看起来像

The code to read the field looks something like

CDatabase Database;
CString sSerialNumber = "00000000";
CString SqlString;

CString sDsn = "Driver={SQL Server};Server=server\\db;Database=Boards;Uid=uid;Pwd=pwd;Trusted_Connection=False";
Database.Open(NULL,false,false,sDsn);

CRecordset recset( &Database );
SqlString.Format("Select SerialNumber from boards where MACAddress = '%s'",mac);
recset.Open(CRecordset::forwardOnly,SqlString,CRecordset::readOnly);
recset.GetFieldValue("SerialNumber",sSerialNumber);

此后,sSerialNumber应该为12345678,但其为1234567

After this, sSerialNumber should be 12345678 but its 1234567

感谢您的帮助

推荐答案

我同意这与驱动程序有关.引入了{SQL Server}驱动程序以用于SQL2000.{SQL Native Client}随2005一起提供.理想情况下,对于2008数据库,您应该使用最新的{SQL Server Native Client 10.0}.较新的驱动程序与旧版本的SQL Server向后兼容.

I'd agree that this is driver related. The {SQL Server} driver was introduced for use with SQL 2000. {SQL Native Client} came along with 2005. Ideally, for your 2008 database, you should use the newest {SQL Server Native Client 10.0}. The newer drivers are backward compatible with older versions of SQL Server.

这篇关于“字符串数据,右截断";选择语句警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆