Search found 19 matches

by paweld
Fri 10 Jun 2022 19:27
Forum: SQL Server Data Access Components
Topic: Table value parameter for TMSStoredProc
Replies: 9
Views: 12228

Re: Table value parameter for TMSStoredProc

An error may occur when retrieving a list of tables because the user may not have permissions.
To rule out a table type handling error on the SDAC side and verify that the user has permissions to the type, try the following code:

Code: Select all

MSQuery1.SQL.Clear;
MSQuery1.SQL.Add(' declare @idtab TT_RawMatlIDs ');
MSQuery1.SQL.Add(' insert into @idtab(RawMatlID) values (1), (2), (3) ');
MSQuery1.SQL.Add(' select * from @idtab ');
try
  MSQuery1.Open;
  MSQuery1.Close;
  ShowMessage('Permissions OK');
except
  on E: Exception do
    ShowMessage('Error: ' + #13#10 + E.Message);
end;
by paweld
Thu 14 Apr 2022 08:53
Forum: SQL Server Data Access Components
Topic: Table value parameter for TMSStoredProc
Replies: 9
Views: 12228

Re: Table value parameter for TMSStoredProc

i don't confirm:

Code: Select all

uses
  MSAccess;
  
procedure TForm1.Button1Click(Sender: TObject);
var
  conn: TMSConnection;
  q: TMSQuery;
  sp: TMSStoredProc;
  td: TMSTableData;
  i: Integer;
begin
  Memo1.Lines.Clear;
  conn := TMSConnection.Create(nil);
  conn.Server := '.';
  conn.Database := 'testdb';
  conn.Username := 'sa';
  conn.Password := '123';
  conn.Connect;
  q := TMSQuery.Create(nil);
  q.Connection := conn;
  q.SQL.Add(' if not exists (select 1 from sys.types where name=''type_table_sdac'' and is_table_type=1) ');
  q.SQL.Add(' create type type_table_sdac as table (id int) ');
  q.ExecSQL;
  q.SQL.Clear;
  q.SQL.Add(' if exists (select 1 from sys.procedures where name=''proc_test_table_type'') ');
  q.SQL.Add(' drop procedure proc_test_table_type ');
  q.ExecSQL;
  q.SQL.Clear;
  q.SQL.Add(' create procedure proc_test_table_type @tab type_table_sdac readonly, @text nvarchar(max) output ');
  q.SQL.Add(' as ');
  q.SQL.Add(' begin ');
  q.SQL.Add(' select @text=stuff((select isnull('', ''+convert(varchar(20), id), '''') from @tab for xml path('''')), 1, 2, '''') ');
  q.SQL.Add(' end ');
  q.ExecSQL;
  sp := TMSStoredProc.Create(nil);
  sp.Connection := conn;
  td := TMSTableData.Create(nil);
  td.Connection := conn;
  td.TableTypeName := 'type_table_sdac';
  td.Open;
  for i := 0 to 9 do
  begin
    td.Insert;
    td.FieldByName('id').AsInteger := Random(999) + 1;
    td.Post;
  end;
  sp.StoredProcName := 'proc_test_table_type';
  sp.ParamByName('tab').AsTable := td.Table;
  sp.Execute;
  for i := 0 to sp.Params.Count - 1 do
  begin
    Memo1.Lines.Add('Param index: ' + IntToStr(i));
    Memo1.Lines.Add('Param name: ' + sp.Params[i].Name);
    Memo1.Lines.Add('Param value: ' + sp.Params[i].Text);
    Memo1.Lines.Add('====================================');
  end;
  sp.Free;
  q.SQL.Clear;
  q.SQL.Add(' if exists (select 1 from sys.procedures where name=''proc_test_table_type'') ');
  q.SQL.Add(' drop procedure proc_test_table_type ');
  q.ExecSQL;
  q.SQL.Clear;
  q.SQL.Add(' if exists (select 1 from sys.types where name=''type_table_sdac'' and is_table_type=1) ');
  q.SQL.Add(' drop type type_table_sdac ');
  q.ExecSQL;
  q.Free;
  conn.Disconnect;
  conn.Free;
end;   
Tested on Lazarus 2.3 with FPC 3.2.2 x86, Windows 10 x64, SDAC 10.0.2 and MSSQL 2017
by paweld
Thu 14 Apr 2022 08:23
Forum: SQL Server Data Access Components
Topic: TMSStoredProc and NVARCHAR(MAX)
Replies: 4
Views: 9106

Re: TMSStoredProc and NVARCHAR(MAX)

I don't confirm:

Code: Select all

uses
  MSAccess;
  
procedure TForm1.Button1Click(Sender: TObject);
var
  conn: TMSConnection;
  q: TMSQuery;
  sp: TMSStoredProc;
  i: Integer;
begin
  Memo1.Lines.Clear;
  conn := TMSConnection.Create(nil);
  conn.Server := '.';
  conn.Database := 'testdb';
  conn.Username := 'sa';
  conn.Password := '123';
  conn.Connect;
  q := TMSQuery.Create(nil);
  q.Connection := conn;
  q.SQL.Add(' if exists (select 1 from sys.procedures where name=''proc_test_max'') ');
  q.SQL.Add(' drop procedure proc_test_max ');
  q.ExecSQL;
  q.SQL.Clear;
  q.SQL.Add(' create procedure proc_test_max @repeat int, @text nvarchar(max) output ');
  q.SQL.Add(' as ');
  q.SQL.Add(' begin ');
  q.SQL.Add(' declare @i int=0 ');
  q.SQL.Add(' select @text='''' ');
  q.SQL.Add(' while @i<@repeat ');
  q.SQL.Add(' select @text=@text+''sample text '', @i=@i+1 ');
  q.SQL.Add(' end ');
  q.ExecSQL;
  sp := TMSStoredProc.Create(nil);
  sp.Connection := conn;
  sp.StoredProcName := 'proc_test_max';
  sp.ParamByName('repeat').AsInteger := 500;
  sp.Execute;
  for i := 0 to sp.Params.Count - 1 do
  begin
    Memo1.Lines.Add('Param index: ' + IntToStr(i));
    Memo1.Lines.Add('Param name: ' + sp.Params[i].Name);
    Memo1.Lines.Add('Param value: ' + sp.Params[i].Text);
    Memo1.Lines.Add('====================================');
  end;
  sp.Free;
  q.SQL.Clear;
  q.SQL.Add(' if exists (select 1 from sys.procedures where name=''proc_test_max'') ');
  q.SQL.Add(' drop procedure proc_test_max ');
  q.ExecSQL;
  q.Free;
  conn.Disconnect;
  conn.Free;
end;
Tested on Lazarus 2.3 with FPC 3.2.2 x86, Windows 10 x64, SDAC 10.0.2 and MSSQL 2017
by paweld
Sat 09 Apr 2022 09:08
Forum: SQL Server Data Access Components
Topic: passing TByteArray via TMSStoredProc
Replies: 2
Views: 8295

Re: passing TByteArray via TMSStoredProc

Code: Select all

procedure TForm1.Button2Click(Sender: TObject);
var
  barr: array of byte;
  i: Integer;
begin
  SetLength(barr, 20);
  for i := 0 to 19 do
    barr[i] := 65 + i;
  MSStoredProc1.StoredProcName := 'test_proc';
  MSStoredProc1.ParamByName('param1').AsString := 'param1';
  MSStoredProc1.ParamByName('param2').SetBlobData(@barr[0], Length(barr));
  MSStoredProc1.ParamByName('param3').AsString := 'param3';
  MSStoredProc1.ParamByName('param4').AsInteger := 0;
  MSStoredProc1.ExecProc;
end;       
by paweld
Thu 31 Mar 2022 08:28
Forum: SQL Server Data Access Components
Topic: Undefined identifier auServer/auWindows
Replies: 2
Views: 8516

Re: Undefined identifier auServer/auWindows

add `MSClasses` to `uses` section
by paweld
Mon 14 Feb 2022 09:15
Forum: SQL Server Data Access Components
Topic: Migration From Ado To Sdac
Replies: 1
Views: 8558

Re: Migration From Ado To Sdac

TMSSQL does not return any records, so you cannot retrieve the data.
Use a TMSQuery component for this purpose, e.g.

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  MSQuery1: TMSQuery;
  i: Integer;
begin
  MSQuery1 := TMSQuery.Create(nil);
  MSQuery1.Connection := MSConnection1;
  MSQuery1.SQL.Text := ' select * from table order by id ';
  MSQuery1.Open;
  Memo1.Lines.Add('Records count: ' + IntToStr(MSQuery1.RecordCount));
  if not MSQuery1.IsEmpty then
  begin
    MSQuery1.First;
    while not MSQuery1.EOF do
    begin
      Memo1.Lines.Add('Record no: ' + IntToStr(i));
      for i := 0 to MSQuery1.FieldCount - 1 do
        Memo1.Lines.Add(MSQuery1.Fields[i].FieldName + ': ' + MSQuery1.Fields[i].AsString);  //or: MSQuery1.FieldByName(MSQuery1.Fields[i].FieldName).AsString
      MSQuery1.Next;
    end;
  end;
  MSQuery1.Close;
end;
by paweld
Mon 29 Jun 2020 13:45
Forum: SQL Server Data Access Components
Topic: Delphi FMX save blob to MSSQL
Replies: 11
Views: 11022

Re: Delphi FMX save blob to MSSQL

FMX.Image.Bitmap is saved as a PNG image, so you must read as png in the VCL application:

Code: Select all

uses
  pngimage;
  
procedure TfrmMain.btn_read_from_DBClick(Sender: TObject);
var 
  BlobStream : TStream;
  png: TPngImage;
begin
  if not MSConnection1.Connected then
    MSConnection1.Connected := true;
    try
      png: TPngImage.Create;
      MSQuery1.Close;
      MSQuery1.SQL.Clear;
      MSQuery1.SQL.Add('select * from sign where id = ''' + edt_id.Text + '''');
      MSQuery1.Open;
      BlobStream := MSQuery1.CreateBlobStream(MSQuery1.FieldByName('image1'),TBlobStreamMode.bmRead);
      BlobStream.Position:=0;
      png.LoadFromStream(BlobStream);  // VCL version
      Image2.Picture.Graphic:=png;
      png.Free;
      BlobStream.Free;
    except
      on E: Exception do
        ShowMessage('Fehler bei lesen blob from DB ' + e.Message);
    end;
end;
by paweld
Thu 31 Oct 2019 07:46
Forum: SQL Server Data Access Components
Topic: TMSconnection - strange behavior
Replies: 1
Views: 2068

Re: TMSconnection - strange behavior

Add to ConnectionString: Login Prompt=False
e.g.

Code: Select all

s:='Provider=TDS;Data Source=localhost;User ID=sa;Password=123;Login Prompt=False';
mscon.ConnectString:=s;
if mscon.LoginPrompt then 
showmessage('loginpromt is set to true') 
else 
showmessage('loginpromt is set to false');
by paweld
Sat 24 Sep 2016 17:41
Forum: SQL Server Data Access Components
Topic: Refreshing field information after database change
Replies: 1
Views: 2293

Re: Refreshing field information after database change

Code: Select all

connection.Database := 'Database1';
query.Connection := connection;
query.SQL.Text := 'SELECT * FROM View';
query.Open;
query.Close;
connection.Database := 'Database2';
query.Fields.Clear;
query.Open; 
by paweld
Tue 17 Feb 2015 12:17
Forum: SQL Server Data Access Components
Topic: query.ParamByName
Replies: 3
Views: 3435

Re: query.ParamByName

Hi,
Did you can solve the problem?
by paweld
Sun 01 Feb 2015 21:15
Forum: SQL Server Data Access Components
Topic: Unique keyfields required on RefreshQuick, how to solve?
Replies: 5
Views: 1870

Re: Unique keyfields required on RefreshQuick, how to solve?

try like this:

Code: Select all

 select s.field1, s.field2, s.field3 from 
(SELECT
  FIELD1,
  FIELD2,
  FIELD3
FROM TABLE (PLUS JOINS)
WHERE CONDITIONS1

UNION ALL

SELECT
  FIELD1,
  FIELD2,
  FIELD3
FROM TABLE (PLUS SAME JOINS AS ABOVE)
WHERE CONDITIONS2) s 
by paweld
Tue 14 Oct 2014 08:51
Forum: SQL Server Data Access Components
Topic: Problem with TinyInt field, SDAC 6.11.22
Replies: 10
Views: 2606

Re: Problem with TinyInt field, SDAC 6.11.22

The application works correctly. I thank for Your help, very much.
I'll be looking for the cause of an error in my Lazarus installation.

Best regards
by paweld
Thu 09 Oct 2014 12:25
Forum: SQL Server Data Access Components
Topic: Problem with TinyInt field, SDAC 6.11.22
Replies: 10
Views: 2606

Re: Problem with TinyInt field, SDAC 6.11.22

I tried on the new installation "windows xp mode" and problem still exists. After compile, i copy application to:
* laptop (win7 x64 + mssql 2008r2 express): in tinyint column get values: -255, -254, -253, -252, -251
* 1st server (win srv 2008 r2 x64 + mssql 2012 express): values: -31487, -31486 etc.
* 2nd server (win srv 2012r2 x64 + mssql 2014 standard): values: -3071, -3070 etc.

Can You send me compiled application, I test it on my computer ?
by paweld
Wed 08 Oct 2014 12:10
Forum: SQL Server Data Access Components
Topic: Problem with TinyInt field, SDAC 6.11.22
Replies: 10
Views: 2606

Re: Problem with TinyInt field, SDAC 6.11.22

I expect results what You show, but i get in tinyint column random values. tested on few servers with different MSSQL versions (2005, 2008r2, 2012)