AnyDAC
ContentsIndexHome
PreviousUpNext
MS SQL Server Questions

The list of questions and answers related to MS SQL Server.

Group
Links
QZ1: SQL Server 2005: is it possible to use the 'Shared Memory' transport with 'SQL Native Client'?

A: In general:

  • check using "Client network utility", that Shared Memory protocol is enabled;
  • use Server=(local) in your connection definition.

 

QZ2: How to get OriginTabName with SQL Server 2005 ?

A: Add ExtendedMetadata=True connection definition parameter. 

 

QZ3: Calling a stored procedure, I am getting »[AnyDAC][Phys][ODBC]-345. Data too large for variable [#3]. Max len = [2], actual len = [14]«. What is wrong ?

A: That happens in most cases, when a stored procedure has a VARCHAR parameter defined without specifying a size. For example: 

 

PROCEDURE ANALYZETABLE @T_OWNER VARCHAR, @T_TABLE VARCHAR AS
DECLARE @FOOBAR INTEGER;
BEGIN
  /* DUMMY PROCEDURE JUST FOR COMPATIBILITY PURPOSE */
  SET @FOOBAR = 1;
END;

 

The following code will work: 

 

with ADStoredProc1 do begin
  FetchOptions.Items := FetchOptions.Items - [fiMeta];
  StoredProcName := 'ANALYZETABLE';
  Params.Clear;
  Params.CreateParam(ftString, 'T_OWNER', ptInput).Size := 20;
  Params.CreateParam(ftString, 'T_TABLE', ptInput).Size := 20;
  Prepare;
  ParamByName('T_OWNER').AsString := '';
  ParamByName('T_TABLE').AsString := TableName;
  ExecProc;
end;

 

Note:

  • Exclude fiMeta from FetchOptions.Items, so AnyDAC will not fetch stored procedure parameters definition. That is required, because ODBC driver describes @T_OWNER VARCHAR as VARCHAR(1).
  • Specify all parameters properties, including Size before Prepare or first ExecProc call.

 

QZ4: Calling a stored procedure, I am getting »[AnyDAC][Phys][ODBC][Microsoft][SQL Server Native Client 10.0][SQL Server]Line 1: Incorrect syntax near '{'«. What is wrong ?

A: It is a known issue. It happens when:

  • Connection is using SQL Server Native Client 2008 ODBC driver;
  • The DBMS is SQL Server 2000;
  • And a stored procedure has a BLOB input parameter.

At moment only workaround is to use SQL Server 2000 ODBC Driver or SQL Native Client 2005, when you are connecting to the Microsoft SQL Server 2000. 

 

QZ5: Calling Array DML command, I am getting »"[AnyDAC][Phys][ODBC][Microsoft][SQL Server Native Client 10.0]String data, length mismatc«. What is wrong ?

A: It is a known for me issue. It seems it is a bug in Microsoft SQL Native Client ODBC driver. For a while, we have not found a proper solution for that. The issue happens, when one of the parameters has a blob data type (ftBlob, ftMemo, etc). As a workaround set ResourceOptions.ArrayDMLSize to 1. 

 

QZ6: Why is the application raising the "Invalid object name '#<my temp table name>'" exception?

A: The AnyDAC application may raise the exception above, when it is working with the Microsoft SQL Server local temporary tables. To demonstrate this, the following code reproduces the issue: 

 

ADQuery1.ExecSQL('select * into #TmpOrd from [Orders]');
ADQuery1.Open('select * from #TmpOrd');

 

To resolve the issue, set TADQuery.ResourceOptions.DirectExecute to True. Also this is required, when application is extensively using:

  • local temporary tables in the client SQL;
  • and/or the dynamic client SQL.

As an option, consider to use global temporary tables. 

 

QZ7: I am getting strange SQL error (8155) "No column was specified for column 1 of 'A' ". What is wrong ?

A: It seems an application sets FetchOptions.RecsMax to a value greater than zero and executes a query with expressions in SELECT list. For example: 

 

SELECT MIN(MyField) FROM MyTable WHERE MyIdField > 0

 

In that case AnyDAC modifies a query to: 

 

SELECT TOP 10 * FROM (
  SELECT MIN(MyField) FROM MyTable WHERE MyIdField > 0
) A

 

On SQL Server this syntax fails with the above error. To resolve this issue, specify the aliases for expressions in SELECT list. 

 

QZ8: I am failing to get Chinese characters (Big5 encoding) from a database. How to fix that ?

A: Try to add connection definition parameter: 

 

ODBCAdvanced=AutoTranslate=no

 

And add the mapping rule: 

 

  object ADConnection1: TADConnection
.....................
    FormatOptions.AssignedValues = [fvMapRules]
    FormatOptions.OwnMapRules = True
    FormatOptions.MapRules = <
      item
        SourceDataType = dtAnsiString
        TargetDataType = dtWideString
      end>
  end

 

Also check that you have set correct Chinese database character set and not Latin1. 

 

QZ9: When I insert a '2011-11-13 00:00' as a datetime value I encounter the error "The conversion of a varchar data type to a datetime data type resulted in an out-of-range value". What am I doing wrong?

A: According to MSDN the used datetime format does not conform to the international standard. There are several solutions to avoid the error:

  1. Using of SET DATEFORMAT option. For example, execute this to set the order of the year, month and day:

 

ADConnection1.ExecSQL('set dateformat ymd');

 

  1. Using CONVERT function:

 

ADConnection1.ExecSQL('insert into Test (date_val) values (convert(datetime, ''2011-11-13 00:00'', 120)');

 

  1. Changing the format of your data to international standard:

 

ADConnection1.ExecSQL('insert into Test (date_val) values(''2011-11-13T00:00:00'');

 

QZ10: Posting updates to SQL Server table, I am getting error "Update command updated [N] instead of [1] record". What may be a reason for that ?

A: In most cases with SQL Server this error happens when the table has a trigger which modifies the DB explicitly, or implicitly by calling a stored procedure which modified the DB. Then AnyDAC receives not the number of records updated by UPDATE command, but the number of records modified by the trigger. 

To avoid that insert SET NOCOUNT ON at trigger beginning. Or set UpdateOptions.CountUpdatedRecords to False. 

 

QZ11: I declared some table columns as DATETIME2 / DATE / TIME and AnyDAC returns them as WideString. Or - I am getting Type mismatch, expecting Date, actual WideString. What is wrong ?

The DATETIME2 / DATE / TIME were introduced in SQL Server 2008. "SQL Server" (SQL Server 2000) ODBC driver does not know these types and maps them to WideStrings. The SQL Server Native Client v 10 knows them and represents correctly. To resolve the issue you should install SQL Server Native Client v 10. It is not installed by default, but "SQL Server" ODBC driver is installed by default.

What do you think about this topic? Send feedback!