I have a problem when I'm running customized report,
I used this query View to generate the report: https://drive.google.com/open?id=0B0Aenr4I_Yz9RWRSN0RtaXhoSG8
After Executing finished, report doesn't work and show the timeout error.
and then I tried to trace this query in the system, and get this query:
SELECT vTranPeriodMultiCury.[BatchNbr], vTranPeriodMultiCury.[RefNbr], vTranPeriodMultiCury.[InvoiceNbr], vTranPeriodMultiCury.[JobOrderNbr], vTranPeriodMultiCury.[Customer_Vendor_ID], vTranPeriodMultiCury.[SourceCredit], vTranPeriodMultiCury.[SourceDebit], vTranPeriodMultiCury.[BaseCredit], vTranPeriodMultiCury.[BaseDebit], vTranPeriodMultiCury.[Module], vTranPeriodMultiCury.[TranDate], vTranPeriodMultiCury.[TranType], vTranPeriodMultiCury.[Customer_Vendor_CD], vTranPeriodMultiCury.[Customer_Vendor_Name], vTranPeriodMultiCury.[TranDesc], vTranPeriodMultiCury.[Curyid], vTranPeriodMultiCury.[CuryRate], vTranPeriodMultiCury.[FinPeriodID], vTranPeriodMultiCury.[AccountCD], vTranPeriodMultiCury.[AccountDesc], vTranPeriodMultiCury.[BaseBegBalSummary], vTranPeriodMultiCury.[BaseEndBalSummary], vTranPeriodMultiCury.[SourceBegBalSummary], vTranPeriodMultiCury.[SourceEndBalSummary], vTranPeriodMultiCury.[BaseBegBalIDR], vTranPeriodMultiCury.[BaseEndBalIDR], vTranPeriodMultiCury.[SourceBegBalIDR], vTranPeriodMultiCury.[SourceEndBalIDR], vTranPeriodMultiCury.[BaseBegBalJPY], vTranPeriodMultiCury.[BaseEndBalJPY], vTranPeriodMultiCury.[SourceBegBalJPY], vTranPeriodMultiCury.[SourceEndBalJPY], vTranPeriodMultiCury.[BaseBegBalUSD], vTranPeriodMultiCury.[BaseEndBalUSD], vTranPeriodMultiCury.[SourceBegBalUSD], vTranPeriodMultiCury.[SourceEndBalUSD], Account.[AccountCD], Account.[Type], Account.[NoteID], NULL, NULL, NULL, Batch.[Module], Batch.[BatchNbr], Batch.[CuryInfoID], Batch.[NoteID], NULL, NULL, NULL FROM vTranPeriodMultiCury vTranPeriodMultiCury LEFT JOIN Account Account ON (Account.CompanyID = 2) AND [Account].[DeletedDatabaseRecord] = 0 AND (vTranPeriodMultiCury.[AccountID] = Account.[AccountID]) LEFT JOIN Batch Batch ON (Batch.CompanyID = 2) AND [Batch].[DeletedDatabaseRecord] = 0 AND (vTranPeriodMultiCury.[BatchNbr] = Batch.[BatchNbr]) WHERE (vTranPeriodMultiCury.CompanyID = 2) AND (vTranPeriodMultiCury.BranchID IS NULL OR vTranPeriodMultiCury.BranchID IN (1, 2, 3)) AND (((vTranPeriodMultiCury.[AccountCD] >= NULL OR NULL IS NULL ) AND (vTranPeriodMultiCury.[AccountCD] <= NULL OR NULL IS NULL ) AND (vTranPeriodMultiCury.[FinPeriodID] = '052017' OR '052017' IS NULL ))) ORDER BY vTranPeriodMultiCury.[AccountCD] ASC, vTranPeriodMultiCury.[Curyid] ASC, vTranPeriodMultiCury.[FinPeriodID] ASC, vTranPeriodMultiCury.[TranDate] ASC, vTranPeriodMultiCury.[BatchNbr] ASC OPTION(OPTIMIZE FOR UNKNOWN)
My question is in which part of web.config should be possible to change the timeout of executing sql query of report designer ?
Probably you should increase this executionTimeOut in Location->system.web->httpRuntime in web.config:
<httpRuntime executionTimeout="300" requestValidationMode="2.0" maxRequestLength="1048576" />
Also try to execute the Following SQL Query on your SQL Server for your Acumatica ERP's database:
use YOUR_DATABASE_NAME
go
exec sp_configure 'remote query timeout (s)',6000
RECONFIGURE WITH OVERRIDE;
Related
I have one Azure SQL server where I have several databases. I need to be able to query across these databases, and have at the moment solves this through external tables. A challange with this solution is that external tables does not support all the same data types as ordinary tables.
According to the following article the solution to incompatible data types are to use other similiar ones in the external table.
https://learn.microsoft.com/en-us/azure/sql-data-warehouse/sql-data-warehouse-tables-data-types#unsupported-data-types.
DDL for table in DB1
CREATE TABLE [dbo].[ActivityList](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Registered] [datetime] NULL,
[RegisteredBy] [varchar](50) NULL,
[Name] [varchar](100) NULL,
[ak_beskrivelse] [ntext] NULL,
[ak_aktiv] [bit] NULL,
[ak_epost] [bit] NULL,
[Template] [text] NULL
CONSTRAINT [PK_ActivityList] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
DDL for external table in DB2
CREATE EXTERNAL TABLE [dbo].[NEMDBreplicaActivityList]
(
[ID] [int] NOT NULL,
[Registered] [datetime] NULL,
[RegisteredBy] [varchar](50) NULL,
[Name] [varchar](100) NULL,
[ak_beskrivelse] [nvarchar](4000) NULL,
[ak_aktiv] [bit] NULL,
[ak_epost] [bit] NULL,
[Template] [varchar](900) NULL
)
WITH (DATA_SOURCE = [DS],SCHEMA_NAME = N'dbo',OBJECT_NAME = N'ActivityList')
Querying the external table NEMDBreplicaActivityList produces the following error
Error retrieving data from
server.database.windows.net.db1. The
underlying error message received was:
'PdwManagedToNativeInteropException ErrorNumber: 46723, MajorCode:
467, MinorCode: 23, Severity: 16, State: 1, ErrorInfo: ak_beskrivelse,
Exception of type
'Microsoft.SqlServer.DataWarehouse.Tds.PdwManagedToNativeInteropException'
was thrown.'.
I have tried defining the ak_beskrivelse column as other external table legal datatypes, such as varchar, with the same result.
Sadly I'm not allowed to edit the data type of columns in the db1 table.
I assume that the error is related to the data type. Any ideas how to fix it?
I solved a similar problem to this by creating a view over the source table which cast the text value as varchar(max), then pointed the external table to the view.
So:
CREATE VIEW tmpView
AS
SELECT CAST([Value] AS VARCHAR(MAX))
FROM [Sourcetable].
Then:
CREATE EXTERNAL TABLE [dbo].[tmpView]
(
[Value] VARCHAR(MAX) NULL
)
WITH (DATA_SOURCE = [myDS],SCHEMA_NAME = N'dbo',OBJECT_NAME = N'tmpView')
Creating the view and casting the text value worked perfect for me 😊
Thank you!
Created view vw_TestReport:
SELECT CAST([Report Date] AS VARCHAR(MAX)) AS [Report Date]
FROM dbo.TestReport
And created external table from view:
CREATE EXTERNAL TABLE [dbo].[TestReport](
[Report Date] [varchar](max) NULL
)
WITH (DATA_SOURCE = [REFToDB],SCHEMA_NAME = N'dbo',OBJECT_NAME = N'vw_TestReport')
We are very new to memsql/mysql and we are trying to play around with a memsql installation.
It is installed on a CentOS7 virtual machine and we are running version 5.1.0 of MemSQL.
We are receiving the error from one of the queries we are attempting:
ERROR 1889 (HY000): Bad distributed join plan: result table shard keys do not match. Please contact MemSQL support at support#memsql.com.
On one of our queries
We have two tables:
CREATE TABLE `MyObjects` (
`Id` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(128) NOT NULL,
`Description` VARCHAR(256) NULL,
`Boolean` BIT NOT NULL,
`Int8` TINYINT NOT NULL,
`Int16` SMALLINT NOT NULL,
`Int32` MEDIUMINT NOT NULL,
`Int64` INT NOT NULL,
`Float` DOUBLE NOT NULL,
`DateCreated` TIMESTAMP NOT NULL,
SHARD KEY (`Id`),
PRIMARY KEY (`Id`)
);
CREATE TABLE `MyObjectDetails` (
`MyObjectId` INT,
`Int32` MEDIUMINT NOT NULL,
SHARD KEY (`MyObjectId`),
INDEX (`MyObjectId`)
);
And here is the SQL we are executing and getting the error.
memsql> SELECT mo.`Id`,mo.`Name`,mo.`Description`,mo.`Boolean`,mo.`Int8`,mo.`Int16`,
mo.`Int32`,mo.`Int64`,mo.`Float`,mo.`DateCreated`,mods.`MyObjectId`,
mods.`Int32` FROM
( SELECT
mo.`Id`,mo.`Name`,mo.`Description`,mo.`Boolean`,mo.`Int8`,
mo.`Int16`,mo.`Int32`,mo.`Int64`,mo.`Float`,mo.`DateCreated`
FROM `MyObjects` mo LIMIT 10 ) AS mo
LEFT JOIN `MyObjectDetails` mods ON mo.`Id` = mods.`MyObjectId` ORDER BY `Name` DESC;
ERROR 1889 (HY000): Bad distributed join plan: result table shard keys do not match. Please contact MemSQL support at support#memsql.com.
Does anyone know why we are receiving this error, and if there is a possible change we can make to help alleviate this issue?
The one thing we do know is it has something to do with the inner select as if I pull it out and do the join it works, however we only get 10 total rows from the join. What we are attempting is getting the top 10 from the main table and include all of the details from the right.
We also tried changing the MyObjectDetails table to have an empty SHARD KEY, but that resulted in the same error.
SHARD KEY()
We also added an auto-incrementing Id column to the details table and put the shard on that column, and yet still received the same error.
Thanks in advance for any help.
UPDATE:
I contacted MemSQL through email (huge props to their customer service by the way -- very fast response time, less than a couple hours)
But from what Mike stated I changed the table to be a REFERENCE table and removed the SHARD KEY part of the create table statement. Once I did this, I was able to run the queries. I am not 100% sure on what ramifications this will have but it fixed my issue at hand. Thanks
CREATE REFERENCE TABLE `MyObjects` (
`Id` INT NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(128) NOT NULL,
`Description` VARCHAR(256) NULL,
`Boolean` BIT NOT NULL,
`Int8` TINYINT NOT NULL,
`Int16` SMALLINT NOT NULL,
`Int32` MEDIUMINT NOT NULL,
`Int64` INT NOT NULL,
`Float` DOUBLE NOT NULL,
`DateCreated` TIMESTAMP NOT NULL,
PRIMARY KEY (`Id`)
);
Thanks to Mike Gallegos for looking into this, adding a summary of his answer here:
The error message here is bad, but the reason for the error is that MemSQL does not currently support a distributed left join where the left side (the Limit subquery in this case) has a LIMIT operator. If you cannot rewrite the query to do the limit after the join, then you could change the MyObjects table to a reference table to work around the issue.
When I try to use the last function (https://msdn.microsoft.com/en-us/library/azure/mt421186.aspx). I get the following error:
Compiling query failed.
SELECT
deviceId
,System.TimeStamp as timestamp
,avg(events.externaltemp) as externaltemp
,LAST(System.Timestamp) OVER (PARTITION BY deviceId LIMIT DURATION(second, 1) when [externaltemp] is not null ) as Latest
INTO
[powerBI]
FROM
[EventHub] as events timestamp by [timestamp]
GROUP BY deviceId, TumblingWindow(second,1)
My last function looks very similar to the one in the msdn sample, so I'm not sure why there is a problem.
You are using [externaltemp] in your query, but it is not included in group by. That is the reason. And "last" function does not allow aggregates inside it, so below wouldn't work as well
LAST(System.Timestamp) OVER (PARTITION BY deviceId LIMIT DURATION(second, 1) when avg([externaltemp]) is not null ) as Latest
It can be achieved by splitting the query into two steps, like this
with DeviceAggregates
as
(
SELECT
System.TimeStamp as [Timestamp],
deviceId,
avg(events.externaltemp) as [externaltemp]
FROM
[EventHub] as events timestamp by [timestamp]
GROUP BY
deviceId,
TumblingWindow(second,1)
),
DeviceAggregatesWithLast as
(
select
*,
last([Timestamp]) over (partition by deviceId limit duration(second,1) when [externaltemp] is not null) [LastTimeThereWasANonNullTemperature]
from
DeviceAggregates
)
select *
INTO
[powerBI]
from
DeviceAggregatesWithLast
I am attempting to create a query that accesses multiple databases on a single server. I am using a cursor to access multiple other linked servers to the base server that the query is run on. The issue that I am running into is the following:
Msg 916, Level 14, State 1, Line 43
The server principal "USER" is not able to access the database "Metals" under the current security context.
Msg 3930, Level 16, State 1, Line 104
The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
Msg 916, Level 14, State 1, Line 43
The server principal "User" is not able to access the database "Metals" under the current security context.
Msg 3930, Level 16, State 1, Line 104
The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
The server shows that I am logged in, so why is the database using "USER" and "User" to attempt to access the "Metals" db?
I believe that the query to access the Metals db is correct because it returns the correct data when running it outside of the dynamic sql code. I think the issue has to do with permissions, but I am unsure which permissions I should be changing for the user. Currently, BLUser only has connect and select permissions. Are there other permissions that I should be adding to allow them to access the Metals db?
The query is as follows:
DECLARE #location as varchar(50)
DECLARE #srv as varchar(20)
DECLARE #alphaDb as varchar(20)
DECLARE LabCursor Cursor FOR
SELECT Location, SQLServer, AlphaDB
FROM Labs
OPEN LabCursor
DECLARE #sql as varchar(max)
CREATE TABLE #tmpCombinedResults
(
Lab varchar(50) NULL,
Department varchar(50) NULL,
Instrument varchar(50) NULL,
Method varchar(50) NULL,
Matrix varchar(50) NULL,
StudyDate datetime NULL,
StudyNumber int NULL
)
FETCH NEXT FROM LabCursor INTO #location, #srv, #alphaDb
WHILE ##FETCH_STATUS = 0
BEGIN
-- query with both metals and alpha
SET #sql =
'
CREATE TABLE #tmpResults
(
Lab varchar(50) NULL,
Department varchar(50) NULL,
Instrument varchar(50) NULL,
Method varchar(50) NULL,
Matrix varchar(50) NULL,
StudyDate datetime NULL,
StudyNumber int NULL
)
INSERT INTO #tmpResults(Department, Instrument, Method, Matrix, StudyDate, StudyNumber)
SELECT t.Dept,
oms.InstrumentID,
oms.Method,
oms.Matrix,
MAX(oms.DateOfStudy) StudyDate,
oms.StudyNum
FROM [' + #alphaDb + '].[dbo].AnalRunSeq ars
INNER JOIN [' + #alphaDb + '].[dbo].ottMDL1Studies oms ON ars.TestNo = oms.Method
INNER JOIN [' + #alphaDb + '].[dbo].Tests t ON ars.TestCode = t.TestCode
INNER JOIN [' + #alphaDb + '].[dbo].AnalRuns ar ON ars.RunID = ar.RunID
AND oms.InstrumentID = ar.InstrumentID
AND oms.Analyst = ar.Analyst
INNER JOIN [' + #alphaDb + '].[dbo].Instruments i ON oms.InstrumentID = i.InstrumentID
WHERE oms.ActiveStudy <> 0
AND oms.TypeOfStudy = ''MDL''
GROUP BY oms.InstrumentID,
oms.Method,
oms.Matrix,
oms.StudyNum,
t.Dept,
i.InActive
HAVING t.Dept Not In
(''sub-org'',''sub'',''subpr'')
AND i.InActive = 0
ORDER BY oms.InstrumentID
--error occurs in this part of the code
IF (SELECT COUNT(*) as Qty FROM ' + #srv + '.master.sys.databases where name = ''MetalData'') > 0
BEGIN
UPDATE #tmpResults
SET Department = ''ME'',
Instrument = ms.InstrumentID,
Method = ms.TestNo,
Matrix = ms.Matrix,
StudyDate = (SELECT MAX(ms.InUseDate)
FROM [Metals].[dbo].MDLStudies ms
WHERE ms.InUseDate = InUseDate)
FROM #tmpResults tmp
INNER JOIN ' + #srv + '.[Metals].[dbo].MDLStudies ms ON tmp.Instrument = ms.InstrumentID
WHERE ms.Active = 1
END
SELECT ''' + #location + ''' AS Lab,
Department,
Instrument,
Method,
Matrix,
StudyDate,
StudyNumber
FROM #tmpResults
ORDER BY Lab, Department, Instrument
DROP TABLE #tmpResults
'
IF DB_NAME() <> #alphaDb
BEGIN
SET #sql = 'EXEC(''' + REPLACE(#sql, '''', '''''') + ''') at ' + #srv
END
INSERT INTO #tmpCombinedResults
EXEC(#sql)
FETCH NEXT FROM LabCursor INTO #location, #srv, #alphaDb
END
CLOSE LabCursor
DEALLOCATE LabCursor
SELECT *
FROM #tmpCombinedResults
DROP TABLE #tmpCombinedResults
The current solutions that I have found on the web, all outlined here didn't work for for me either. This one in particular didn't make sense because I don't see Databases as an option in the left column of the Object Explorer Details.
Any help to solve this issue would be greatly appreciated!
This issue was caused by the user not having proper permissions in two of the five servers that were being referenced by the cursor. Once the permissions were corrected, the issue was resolved.
I have the following code:
var statList = (from i in _dbContext.Screenshots
where EntityFunctions.TruncateTime(i.dateTimeServer.Value) >= startDate && EntityFunctions.TruncateTime(i.dateTimeServer.Value) <= endDate
group i by EntityFunctions.TruncateTime(i.dateTimeServer.Value)
into g
select new ScreenshotStatistic()
{
Date = g.Key.Value,
AllScreenshots = g.Count(),
ScreenshotsNoSilent = g.Where(p => p.version.IndexOf("silent") == 0).Count(),
ScreenshotsNoSilentWithViews = g.Where(p => p.version.IndexOf("silent") == 0 && p.viewsPage + p.viewsOriginal > 0).Count(),
ScreenshotsOnlySilent = g.Where(p => p.version.IndexOf("silent") >= 0).Count(),
ScreenshotsOnlySilentWithViews = g.Where(p => p.version.IndexOf("silent") >= 0 && p.viewsPage + p.viewsOriginal > 0).Count(),
ScreenshotsOnlyUploadViaSite = g.Where(p => p.version.IndexOf("UPLOAD_VIA_SITE") >= 0).Count(),
ScreenshotsOnlyUploadViaSiteWithViews = g.Where(p => p.version.IndexOf("UPLOAD_VIA_SITE") >= 0 && p.viewsPage + p.viewsOriginal > 0).Count()
}).ToList();
It works carefully for my local database, but I get "Operation timeout" when I try to connect to SQL Azure. As I understand, my request is not optimized. How can I do the request better?
table has the following structure:
CREATE TABLE [dbo].[Screenshots](
[id] [int] IDENTITY(1,1) NOT NULL,
[dateTimeClient] [datetime] NOT NULL,
[name] [nvarchar](500) NOT NULL,
[username] [varchar](50) NULL,
[filename] [nvarchar](50) NULL,
[description] [nvarchar](500) NULL,
[version] [varchar](50) NULL,
[lang] [varchar](50) NULL,
[dateTimeServer] [datetime] NULL CONSTRAINT [DF_Screenshots_dateTimeServer] DEFAULT (getdate()),
[isPublic] [bit] NOT NULL CONSTRAINT [DF_Screenshots_isPublic] DEFAULT ((0)),
[viewsPage] [int] NOT NULL CONSTRAINT [DF_Screenshots_viewsPage_1] DEFAULT ((0)),
[viewsThumb] [int] NOT NULL CONSTRAINT [DF_Screenshots_viewsThumb_1] DEFAULT ((0)),
[viewsOriginal] [int] NOT NULL CONSTRAINT [DF_Screenshots_viewsOriginal_1] DEFAULT ((0)),
[statusID] [int] NOT NULL,
CONSTRAINT [PK_Screenshots] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Screenshots] WITH CHECK ADD CONSTRAINT [FK_Screenshots_ScreenshotStatuses] FOREIGN KEY([statusID])
REFERENCES [dbo].[ScreenshotStatuses] ([ID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Screenshots] CHECK CONSTRAINT [FK_Screenshots_ScreenshotStatuses]
GO
EntityFunctions.TruncateTime is being translated into:
convert (datetime2, convert(varchar(255), [dateTimeServer], 102) , 102)
This is causing your query to be non-sargable, resulting in slow performance and timeout. I recommend making the following changes
First off, I do not see why you need to truncate the time in your where clause. I suggest you make this change:
where i.dateTimeServer.Value >= startDate && i.dateTimeServer.Value <= endDate
This will prevent the database from having to run the function on every record.
If the query still times out, I would change the group by to:
group i by new {
i.dateTimeServer.Value.Year,
i.dateTimeServer.Value.Month,
i.dateTimeServer.Value.Day
}
Functionally this is the same, but I believe it produces a more friendly translation:
DATEPART (year, dateTimeServer), DATEPART (month, dateTimeServer) etc..
Add an index to dateTimeServer
If all else fails, you will need to add a column to your table with the time portion truncated. Index it and use it in your query.