Problem with auto new connection
Problem with auto new connection
Hi, I have 2 queries:
Q1, Q2: TMSQuery;
Q1.SQL.Add('SELECT 0 SELECT 1')'
Q2.SQL.Add('SELECT 2');
Q1.Active := True; -> open connection with one SPID
Q2.Active := True; -> open the second connection with another SPID
Q1.Fields[0].AsInteger returns 0, so the SELECT 1 is still waiting...
Is it possible to avoid this situation? It can be mistake in SQL script and I don't want to open the second connection.
I want this:
Q1.Fields[0].AsInteger returns 0 (SELECT 1 and all next are discarded) and only one connection is alive (one SPID).
Thanks a lot
Roman
Q1, Q2: TMSQuery;
Q1.SQL.Add('SELECT 0 SELECT 1')'
Q2.SQL.Add('SELECT 2');
Q1.Active := True; -> open connection with one SPID
Q2.Active := True; -> open the second connection with another SPID
Q1.Fields[0].AsInteger returns 0, so the SELECT 1 is still waiting...
Is it possible to avoid this situation? It can be mistake in SQL script and I don't want to open the second connection.
I want this:
Q1.Fields[0].AsInteger returns 0 (SELECT 1 and all next are discarded) and only one connection is alive (one SPID).
Thanks a lot
Roman
-
- Devart Team
- Posts: 925
- Joined: Thu 17 Nov 2005 10:53
Unit1.pas:
Unit1.dfm:
You have to fill server name, start application and click button Start.
SDAC 4.70.0.48
Delphi 2009 Update 3 (DB Pack Update 4)
SQL Server 2005 SP 3 / 2008
Native client 2005 / 2008
Profiler 2008:
Regards
Roman
Code: Select all
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, MemDS, DBAccess, MSAccess, Grids, DBGrids, StdCtrls;
type
TForm1 = class(TForm)
MSConnection1: TMSConnection;
MSQuery1: TMSQuery;
MSQuery2: TMSQuery;
Button1: TButton;
DBGrid1: TDBGrid;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
MSQuery1.Active := True;
MSQuery2.Active := True;
end;
end.
Code: Select all
ClientHeight = 335
ClientWidth = 427
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 265
Top = 60
Width = 75
Height = 25
Caption = 'Start'
TabOrder = 0
OnClick = Button1Click
end
object DBGrid1: TDBGrid
Left = 60
Top = 190
Width = 320
Height = 120
DataSource = DataSource1
TabOrder = 1
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'Tahoma'
TitleFont.Style = []
end
object MSConnection1: TMSConnection
Database = 'tempdb'
Authentication = auWindows
Left = 90
Top = 55
end
object MSQuery1: TMSQuery
Connection = MSConnection1
SQL.Strings = (
'select 0 select 1')
Left = 135
Top = 55
end
object MSQuery2: TMSQuery
Connection = MSConnection1
SQL.Strings = (
'select 2')
Left = 180
Top = 55
end
object DataSource1: TDataSource
DataSet = MSQuery1
Left = 115
Top = 140
end
end
SDAC 4.70.0.48
Delphi 2009 Update 3 (DB Pack Update 4)
SQL Server 2005 SP 3 / 2008
Native client 2005 / 2008
Profiler 2008:
Code: Select all
27
1
10
18
16
17
13
12
14
2009-08-18T18:54:16.397+02:00
-- network protocol: LPC
set quoted_identifier on
set arithabort off
set numeric_roundabort off
set ansi_warnings on
set ansi_padding on
set ansi_nulls on
set concat_null_yields_null on
set cursor_close_on_commit off
set implicit_transactions off
set language us_english
set dateformat mdy
set datefirst 7
set transaction isolation level read committed
Project1.exe
52
2009-08-18T18:54:20.417+02:00
SET LOCK_TIMEOUT 2000
0
0
Project1.exe
52
2009-08-18T18:54:20.417+02:00
0
0
SET NO_BROWSETABLE ON
0
0
Project1.exe
52
2009-08-18T18:54:20.417+02:00
0
0
select 0 select 1
0
0
Project1.exe
52
2009-08-18T18:54:20.417+02:00
0
0
-- network protocol: LPC
set quoted_identifier on
set arithabort off
set numeric_roundabort off
set ansi_warnings on
set ansi_padding on
set ansi_nulls on
set concat_null_yields_null on
set cursor_close_on_commit off
set implicit_transactions off
set language us_english
set dateformat mdy
set datefirst 7
set transaction isolation level read committed
Project1.exe
53
2009-08-18T18:54:20.427+02:00
SET NO_BROWSETABLE ON
0
0
Project1.exe
53
2009-08-18T18:54:20.427+02:00
0
0
select 2
0
0
Project1.exe
53
2009-08-18T18:54:20.43+02:00
0
0
3000
0
Project1.exe
53
2009-08-18T18:54:20.427+02:00
0
0
8693000
0
Project1.exe
52
2009-08-18T18:54:20.417+02:00
0
0
Roman
-
- Devart Team
- Posts: 925
- Joined: Thu 17 Nov 2005 10:53
-
- Devart Team
- Posts: 925
- Joined: Thu 17 Nov 2005 10:53
Hi,
I did some investigation a found this solution. But I don't know if it is OK...
Is it possible to use that code?
Can you add to TCustomMSDataSet (or to some predecessor)
I cannot see all relationships in your code and I don't want to generate some Access Violation Error...
Thanks a lot
Roman
I did some investigation a found this solution. But I don't know if it is OK...
Code: Select all
type
TMyMSQuery = class(TMSQuery)
public
procedure Execute; override;
end;
procedure TMyMSQuery.Execute;
begin
inherited;
// if there is a next result set then discard it
if (FICommand nil) and (not FICommand.IUnknownNextIsNull) then
begin
FICommand.ClearIMultipleResults;
FICommand.ClearIUnknownNext;
end;
end;
Can you add to TCustomMSDataSet (or to some predecessor)
Code: Select all
function IsNextResultSet: Boolean;
procedure FreeNextResultSet;
Thanks a lot
Roman
Hi,
I tried build 51 with DisableMultiplyResults and found a problem.
Let's have a sql query (for example):
In this case I get error 'Query must return exactly one result set - use Execute'. So I use Execute. But after Execute MyQuery.FieldCount = 0...
In this case all works OK. HasNextResultSet = False and FieldCount = 1.
I think that is some mistake in implementation of Options.DisableMultiplyResults. USE [dbname] doesn't return any result set, so SELECT 1 shouldn't be ignored.
Thanks
Roman
I tried build 51 with DisableMultiplyResults and found a problem.
Let's have a sql query (for example):
Code: Select all
var
MyQuery: TMSQuery;
with MyQyery do
begin
SQL.Add(
'USE MyDtabase'#13+
'SELECT 1');
Options.DisableMultiplyResults := True;
Open;
end;
Code: Select all
var
MyQuery: TMSQuery;
with MyQyery do
begin
SQL.Add(
'USE MyDtabase '#13+
'SELECT 1');
Options.DisableMultiplyResults := False;
Open;
if HasNextResultSet then
raise Exception.Create('...HasNextResultSet...');
end;
I think that is some mistake in implementation of Options.DisableMultiplyResults. USE [dbname] doesn't return any result set, so SELECT 1 shouldn't be ignored.
Thanks
Roman