|
Hi Pankaj
Your SP would probably run faster if written as:
-----------------------------------------
CREATE PROCEDURE DeleteTicketData @ticketNum INT
AS BEGIN
DECLARE @testVorgangID INT
DELETE FROM TestVorgangEinleseFehler_T
WHERE TicketNumber = @ticketNum
SELECT @testVorgangID = TestVorgangID
FROM TestTickets_T
WHERE TestTicketID = @ticketNum
IF (@testVorgangID IS NOT NULL) BEGIN
DELETE FROM TestVorgaenge_T
WHERE TestVorgangID = @testVorgangID
DELETE FROM TestAktionen_T WHERE TestID IN (
SELECT TestID FROM Tests_T
WHERE TestVorgangID = @testVorgangID)
DELETE FROM TestDSPACETable_T Where TestID IN (
SELECT TestID FROM Tests_T
WHERE TestVorgangID = @testVorgangID)
DELETE FROM TestEreignisse_T Where TestID IN (
SELECT TestID FROM Tests_T
WHERE TestVorgangID = @testVorgangID)
DELETE FROM TestZustaende_T Where TestID IN (
SELECT TestID FROM Tests_T
WHERE TestVorgangID = @testVorgangID)
DELETE FROM Tests_T
WHERE TestVorgangID = @testVorgangID
END
END
GO --------------------------------------------------------
SQL-Server tends to hand set-operations much faster than cursor-based operations.
Additionally, you might want to look at the "timeout" property of your command object. This defines how long your client will wait before assuming that your stored-procedure has taken too long.
Hope this helps.
Andy
|
|
|
|
|
Hi Andy,
You and Mike are right on target. The stored procedure performs much faster with your suggested improvement and the ADO Command object had a CommandTimeOut property that I was not aware of.
Thanks a mega ton
Pankaj
Without struggle, there is no progress
|
|
|
|
|
Firstly, Query Analyzer never times out - it keeps the connection open until SQL Server finishes responding. I believe osql is the same.
You don't say what API you're using to talk to SQL Server - ADO, OLE DB, ODBC, ... There's probably an option in the API to set a general timeout for communications with the database. You could extend this for a long-running query.
You should become familiar with the set-based versions of DELETE . The DELETE statement is very powerful and can handle any condition in the WHERE clause, not just equalities. I would rewrite your procedure as
CREATE PROCEDURE DeleteTicketData
@ticketNum int AS
declare @testVorgangID int
-- delete errors
DELETE FROM TestVorgangEinleseFehler_T WHERE TicketNumber = @ticketNum
Select @testVorgangID = TestVorgangID from TestTickets_T WHERE TestTicketID = @ticketNum
IF (@testVorgangID IS NOT NULL)
BEGIN
DELETE FROM TestVorgaenge_T WHERE TestVorgangID = @testVorgangID
-- You could create a temporary table or table variable
-- for the SELECT part here
DELETE FROM TestAktionen_T WHERE TestID IN
( SELECT TestID FROM Tests_T WHERE TestVorgangID = @testVorgangID )
DELETE FROM TestDSPACETable_T WHERE TestID IN
( SELECT TestID FROM Tests_T WHERE TestVorgangID = @testVorgangID )
-- repeat for other tables
DELETE FROM Tests_T WHERE TestVorgangID = @testVorgangID
END
GO In general, set-based operations run far faster than cursor-based operations.
|
|
|
|
|
Hi,
You have been of (super-duper * 1000) help. Not only did you point me in the right direction about restructuring the SQL, but you were right about the CommandTimeOut property. I thought the setting on the SQL Server side was enough, but as usual incomplete knowledge proved dangerous
Thanks a lot,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
I wanna make a dbf file (foxpro database) from mdf(sql server database) with all data that are in it.
Is it possible? if yes how can I do that?
Thanks
|
|
|
|
|
You can use "Import AND Export Wizard" if you have SQL SERver2000.
Mazy
No sig. available now.
|
|
|
|
|
In Developer Studio Enterprise Architect you can run SQL scripts right from within the UI. In Dev Studio Professional, you can only run single statements in the query editor, and the "SQL View" completely re-formats the SQL each time you run it.
My question is, is there any way to get Dev Studio Professional to let you run full SQL scripts (from an SQL file rather than from that query view) like in the Enterprise Architect version without upgrading to the higher version? Is there an expansion that Microsoft (or anyone else) might sell just to allow that one feature?
Thanks!
~Steve
|
|
|
|
|
Hi All,
When we double click a .udl file it opens the configuration dialog for connectionstring. What if i would like to open this dialog box at runtime using C# or VB.net?
Thanx in advance.
sorry for my bad English.
|
|
|
|
|
Write click on your .udl file and choose OPEN WITH--->CHOOSE PROGRAM and then choose VS.NET to open it.
Mazy
No sig. available now.
|
|
|
|
|
Hi,
Infact i wana say that i would like to openthe UDL dialog on soem event e.g OnButton_Click eent i would like to Open this dialog and retrieve the connection string.
Can u provide some clue.
Thanx in Advance
sorry for my bad English.
|
|
|
|
|
I think this will work:
Process.Start("path to VS.NET","path to your .udl file");
But I'm not exactly sure ,maybe you need to pass file path in first argument too.
Mazy
No sig. available now.
|
|
|
|
|
Actually, he just wants to open the file with its associated program / shell handler, so the following should be used:
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "path/to/file.udl";
psi.UseShellExecute = true;
Process.Start(psi); ShellExecute(Ex) is what is executed when you double-click a file (or do whatever is the default action based on shell settings). You can also pass different verbs, like "open", "edit", "print", etc., so long as they are supported by the file type association in the registry.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Take a look at: HOW TO: Build a Connection String Programmatically in ADO.NET by Using Visual C# .NET[^]
For a more reusable sample, try this code:
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using ADODB;
using MSDASC;
public sealed class DataLinkDialog : CommonDialog
{
private string _connectionString;
public DataLinkDialog(string connectionString)
{
_connectionString = connectionString;
}
public DataLinkDialog()
{
_connectionString = string.Empty;
}
public string ConnectionString
{
get { return _connectionString; }
set { _connectionString = value; }
}
public override void Reset()
{
_connectionString = string.Empty;
}
protected override bool RunDialog(IntPtr hwndOwner)
{
DataLinks dl = new DataLinksClass();
try
{
if (null == _connectionString || 0 == _connectionString.Length)
{
object ret = dl.PromptNew();
if (null == ret)
{
return false;
}
else
{
_connectionString = ((ADODB._Connection)ret).ConnectionString;
Marshal.ReleaseComObject(ret);
return true;
}
}
else
{
Connection cn = new ConnectionClass();
object ocn = cn;
try
{
cn.ConnectionString = _connectionString;
if (dl.PromptEdit(ref ocn))
{
_connectionString = cn.ConnectionString;
return true;
}
else
{
return false;
}
}
finally
{
Marshal.ReleaseComObject(cn);
}
}
}
finally
{
Marshal.ReleaseComObject(dl);
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
|
|
|
|
|
I am working on optimizing an application that uses stored procedures heavily.
Almost every procedure starts with:
SET DATEFORMAT dmy which causes a recompilation during the procedure execution. It takes about 5 seconds.
Is there any way to set the dmy as a default setting on the startup of the application? Any other ideas how to solve this problem?
I use MS SQL Server 2000.
modified on Monday, August 30, 2010 6:32 AM
|
|
|
|
|
I know Oracle has a default date format that is set as part of the database configuration. I would suspect the same is true for SQL Server, but I'm not up on it. Either I try to avoid depending upon defaults when writing a stored procedure. In the long run, you will have less headaches if within your procedure, you translate between the strings and date types using explicit formats. For example;
convert a date to a string
to_char(some_date_field,'dmy')
convert a string to a date
to_date(some_char_field,'dmy')
Chris Meech
It's much easier to get rich telling people what they want to hear. Christopher Duncan
I can't help getting older, but I refuse to grow up. Roger Wright
I've been meaning to change my sig. Thanks! Alvaro Mendez
We're more like a hobbiest in a Home Depot drooling at all the shiny power tools, rather than a craftsman that makes the chair to an exacting level of comfort by measuring the customer's butt. Marc Clifton
|
|
|
|
|
Chris Meech wrote:
In the long run, you will have less headaches if within your procedure, you translate between the strings and date types using explicit formats
I thought about it. However, the problem is that my task is to optimize a system that uses many stored procedures written by different people. I would have to go through all the procedures (I haven't written any of them!) and find places where using converting functions is necessary.
Sounds like a nightmare to me.
modified on Monday, August 30, 2010 6:32 AM
|
|
|
|
|
I'd recommend using invariant date formats throughout: yyyymmdd.
You could also set the default language database option - see this article in Books Online[^] for more details.
|
|
|
|
|
Mike Dimmick wrote:
You could also set the default language database option
Great idea!
I did not know it sets not only the language but also the date format.
Thanks.
modified on Monday, August 30, 2010 6:33 AM
|
|
|
|
|
Can somebody recommend a SQL data structure that would "describe" a simple HTML table as shown below?
Section 1 | Section 2 | Section 3 | Section 4 |
|
|
|
|
|
Think about what the entities are and their relationship. Also think about what attributes each entity has.
From the example given:
Table, Tr and Td are the entities.
Table is the parent of Tr
Tr is the parent of Td
Td has the attribute colspan
Td has the attribute InnerText (i.e. "Section 1", "Section 2" etc.)
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
Enumerators in .NET: See how to customise foreach loops with C#
|
|
|
|
|
Hello
I have a problem, im running mysql and mysqldump command-line exes from my application. i need: to know if the operation succeded from my application, is there a way to know the last error ocurred?
other quertion: i used the --html option, but the output is still plain text, any ideas?
here is one of the commands i execute:
mysql --host=laura --user=avs_db_user --password=faceshape --verbose --html --database=avs_db -e " source c:\backup\aaa.sql" > output.htm
thanks
|
|
|
|
|
In SQLServer when I want column that start between range of a to b I use this syntax:
column LIKE '[a-b]%'
But it seems that it does not worl correctly in Access. How should I get that query in Access?
Mazy
No sig. available now.
|
|
|
|
|
try:
column LIKE '[a-b]*'
|
|
|
|
|
Nope,I found it some days before, MS ACCESS does not support range for LIKE. I should use it seprately:"[a]% AND [b]%" And I donna why '%' works but '*' doesn't work cause as you said '*' is correct. Any way, thanks for your reply.
Mazy
No sig. available now.
|
|
|
|
|
Mazdak wrote:
MS ACCESS does not support range for LIKE.
how comes ?
open the sample database northwind (comes with access) and try this query :
SELECT lastname
FROM Employees
where lastname like '[a-d]*'
results :
Last Name:
Davolio
Buchanan
Callahan
Dodsworth
|
|
|
|