SQL Server 2012 Stored Procedure timing out. How to fix it? - stored-procedures

Context: SQL Server 2012, Windows Server 2008 R2 (64bit), 2 cores, lots of RAM and HD space,
ADODB via JScript (not .NET)
These really simple stored procedures keep timing out. It's not like I have a lot of records either (from a server point of view): 100,000 or so.
CREATE PROCEDURE [dbo].[Transfer_Part1]
AS
SET NOCOUNT ON
INSERT INTO Primary.dbo.Post
SELECT *
FROM Secondary.dbo.Pre
WHERE HrefProcessed = (-1)
AND ReferrerProcessed = (-1);
CREATE PROCEDURE [dbo].[Transfer_Part3]
AS
SET NOCOUNT ON
DELETE
FROM Secondary.dbo.Pre
WHERE HrefProcessed = (-1)
AND ReferrerProcessed = (-1);
Is there anything I can do to stop getting these messages?
[Microsoft][ODBC SQL Server Driver]Query timeout expired
EXEC Transfer_Part1
[Microsoft][ODBC SQL Server Driver]Query timeout expired
EXEC Transfer_Part3

Do you have an 2-column index on HrefProcessed and ReferrerProcessed?
Also see Bulk DELETE on SQL Server 2008 (Is there anything like Bulk Copy (bcp) for delete data?) for the second one.

Related

Java Web with Weblogic, DB Informix stored procedure data — impossible problem

I have Java Web on Weblogic; database is Informix.
The process is as follows:
User query data.
Create serial(only).
Using stored procedure with serial.
SP content like:
insert reporttable
select data from table1
insert reporttable
select data from table2
if(reporttable.count==0)
insert reporttable select 'NO DATA'
Query reporttable with serial.
Show on Web.
Important problem:
table1 has data count 10(data1,data2.......data10)
reporttable result data count 3(data1, data2, NO DATA) impossible
Important!!! The implementation does not process any exceptions.
When the problem occurs, any query on the data shows the same problem.
But when I restart Weblogic (using the same parameters), the query has no problem.
I have no idea to solve the problem; can you help?
I find the error reason.
Test : rename table name
sp use table1、table2、table3
unknown reason maybe abnormal connection
java.sql.SQLSyntaxErrorException: [FMWGEN][Informix JDBC Driver][Informix]The
specified table (table1) is not in the database.
Error message only trigger on first
Execute sp again,no error, and executeing neglect table1
weblogic restart jndi connection
Execute sp result normal

Working on different database from stored procedure in SQL Server 2008 R2

Please do me a favor, I want to maintain all the stored procedures in one database, let's say SP_Dbase.
I plan this scheme, user application determine dbase_xyz and will go to SP_stored_procedure in SP_Dbase and then retrieve or edit data of dbase_xyz.
Since command Use dbasename does not work in a stored procedure, I have big difficulty.
I don't intend to write down all the procedure as an execute command as follows :
Set #cmd = 'select .... from ' + #DB + '.dbo.tablename'
EXEC(#cmd)
Anyone could help me ?
Note: All databases have same structure and exist in one SQL Server 2008 R2 instance.
Thanks

Informix select first 250000 then the last 250000 records in a table

I work on a CFML script to backup some data in a CSV file from Informix database. The problem is the table has many records 286906 and my scripts timeouts (even I set it not to), the best I could successfully was 260000 with:
SELECT FIRST 260000
APE1, APE2, CALLE, CODPOSTAL, DNI, FCADU, FENACI, LOCALIDAD, NOMBRE, NSS, PROV, TELEFONO
FROM
mytable WHERE FCADU IS NOT NULL AND FENACI IS NOT NULL
is there any way to select the rest of 260000 and then the rest?
I tried with:
SELECT SKIP 260000 FIRST 520000
APE1, APE2, CALLE, CODPOSTAL, DNI, FCADU, FENACI, LOCALIDAD, NOMBRE, NSS, PROV, TELEFONO
FROM
mytable WHERE FCADU IS NOT NULL AND FENACI IS NOT NULL
but I get Error Executing Database Query. A syntax error has occurred.
You can use the Unload statement for creating a file from database:
UNLOAD TO 'mytable.txt' SELECT * FROM mytable;
Maybe that this not works in CFML environment. So you can create a stored procedure which unloads your data.
See unload statement in stored procedure
Is it your script timing out or your database connection? From your question it sou ds to me like its not the coldfusion template that is timing out but the cfquery connection to the database. There is a timeout attribute for the cfquery tag. However apparently it is not reliable a better option is to configure the timout in the advanced section of the datasource within the coldfusion administrator.
Charlie Arehart blogged about this feature here:
http://www.carehart.org/blog/client/index.cfm/2010/7/14/hidden_gem_in_cf9_admin_querytimeout

Delphi update DateTime column in SQL Server 2008 R2

I am trying to post a date to a dateTime column in a SQL Server 2008 R2 database, but I have run into many problems that I don't know what are the causes.
First, I used this code but I got the error:cannot convert string to date.
ADOOF.SQL.Text:='UPDATE OFTab SET CA='''+ CA.Text + ''', demandeClient=''' + DateTimeToStr(demandeClient.DateTime) + ''' WHERE ID='''+ ADOOF.FieldByName('ID') + '''';
ADOOF.ExecSQL;
Second, I have used parameters:
ADOOF.SQL.Text:='UPDATE OFTab SET CA='''+ CA.Text + ''', demandeClient=:demande_client WHERE ID='''+ ADOOF.FieldByName('ID') + '''';
ADOOF.Parameters.ParamByName('demande_client').Value:= demandeClient.Date;
ADOOF.ExecSQL;
But I got the error: Parameter (demande_client) not found.
I googled this problem and I found a suggestion by Embarcadero saying that the parametres sould be created before calling the ADOQuery like this:
ADOOF.SQL.Text:='UPDATE OFTab SET CA='''+ CA.Text + ''', demandeClient=:demande_client WHERE ID='''+ ADOOF.FieldByName('ID') + '''';
ADOOF.Parameters.ParseSQL(ADOOF.SQL.Text, True);
ADOOF.Parameters.ParamByName('demande_client').Value:= demandeClient.Date;
ADOOF.ExecSQL;
Finely I removed the connection Persist Security Info but always the same problem.
Please, any suggestions.
INFO: I am using MICROSOFT OLE DB Provider For SQL Server.
in your first example use
FormatDateTime('YYYYMMDD hhmmss',demandeClient.DateTime)
instead of
DateTimeToStr(demandeClient.DateTime)
This is because DateTimeToStr without formatsettings uses your localized machine settings and your database just might or might not like the format. Using FormatDateTime also gets rid of ambiguities: consider 01/02/03, for some people on the world this is january 2nd 2003 but for others 1st of februari 2003 and even some will say 2001, februari 3rd. YYYYMMDD is universal. 20030201 is always 1st of februari 2003.
It can depend on how you connect to your DB (drivers).
You can try to explicit that you are using a Date:
ADOOF.Parameters.ParamByName('demande_client').DataType:= ftDateTime;
ADOOF.Parameters.ParamByName('demande_client').AsDateTime:= demandeClient.Date;
I will strongly suggest to use SQL Native Client 11 when you are working with SQL Server 2008 R2. New SQL Server 2008 data types (including DATE, TIME, DATETIME2, and DATETIMEOFFSET) are not supported by the SQL Server 2000 OLEDB provider.
Your second code sample should work. Check that you have TADOQuery.ParamCheck = True.

Delphi TClientDataSet "Trying to modify read-only field" error in SQL Server 2008, OK in 2000

Embarcadero® Delphi® 2010 Version 14.0.3593.25826
We are attempting to move a database from SQL Server 2000 to SQL Server 2008. I have a TClientDataSet that is loaded with a SELECT that includes a computed column, i.e., "SELECT Comp_Col = Column1 + ' ' + Column2...".
Running against an SQL Server 2000 database, I can modify the value of the column in the TClientDataSet using the following code:
ClientDataSet1.Edit();
ClientDataSet1.FieldByName('Comp_Col').ReadOnly := false;
ClientDataSet1.FieldByName('Comp_Col').Value := 'MODIFIED';
ClientDataSet1.FieldByName('Comp_Col'').ReadOnly := true;
ClientDataSet1.Post(); // <-- EXCEPTION in 2008
Running against an SQL Server 2008 database, though, I get a "Trying to modify read-only field" error when executing .Post().
I have tried also setting .ProviderFlags = '[]' for the column (in addition to .ReadOnly = false) in the above code, but still get the error. I have also tried setting .ReadOnly = false and .ProviderFlags = '[]' at design-time via the IDE, but this does not help either.
Anybody know how to set a computed column in a TClientDataSet when running against an SQL Server 2008 database?
Thanks!
* UPDATE: ANSWERED *
I discovered the problem--or at least a workaround...
I WAS setting .ReadOnly = false for the column in the TClientDataSet object. This worked with SQL Server 2000 but not with SQL Server 2008.
If I set .ReadOnly = false in for the column instead in the TADOQuery object that is serving as the provider, then I am able to set the value of the computed column in the TClientDataSet object at run-time.
Not ideal for me since this was implemented in a generic function for TClientDataSet objects (that didn't anything about the provider), but it will have to do for now.
I discovered the problem--or at least a workaround . . .
I WAS setting .ReadOnly = false for the column in the TClientDataSet object. This worked with SQL Server 2000 but not with SQL Server 2008.
If I set .ReadOnly = false for the column instead in the TADOQuery object that is serving as the provider, then I am able to set the value of the computed column in the TClientDataSet object at run-time.
Not ideal for me since this was implemented in a generic function for TClientDataSet objects (that didn't anything about the provider), but it will have to do for now.
My experience shows that the creation of ClientDataSet fields by calling TClientDataSet.CreaeteDataSet initially without ReadOnly flags solves the problem. After opening ClientDataSet fields' ReadOnly flags can be returned to their seats for the proper functioning of data-aware controls.

Resources