|
PIEBALDconsult wrote:
It is still preferable to use Open to get the
connection from the pool and Close to return it.
I would say it is the only way.
|
|
|
|
|
Yip, agreed, see the reply I posted to my own question with speed tests on various approaches, and reference to Eddy's link - Thanks!
|
|
|
|
|
 Hi Guys - thanks to all for the responses.
I think the link Eddy posted puts a lot into perspective, in that closing the connection does not really kill it, it leaves it in the pool, and unless there is something in the connection that changes, like accessing a different database, or using a different User ID the same connection from that pool is used again.
I tried inserting 10000 records (on server on local machine) in three different ways.
The difference was only about 100ms
private void cmdInsert_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
string cnStr = "Data Source=" + Server + ";Initial Catalog=" + Database + ";User Id=" + DBUser + "; Password=" + DBPass + ";";
string strSql = "Insert INTO dbo.SpeedTest (Mydata) VALUES ('Hello')";
sw.Start();
using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(cnStr))
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strSql, cn);
for (int i = 0; i < 10000; i++)
{
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
}
sw.Stop();
this.txtResults.Text = sw.ElapsedMilliseconds.ToString();
}
private void cmdInsert_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
string cnStr = "Data Source=" + Server + ";Initial Catalog=" + Database + ";User Id=" + DBUser + "; Password=" + DBPass + ";";
string strSql = "Insert INTO dbo.SpeedTest (Mydata) VALUES ('Hello')";
sw.Start();
using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(cnStr))
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strSql, cn);
cn.Open();
for (int i = 0; i < 10000; i++)
{
cmd.ExecuteNonQuery();
}
cn.Close();
}
sw.Stop();
this.txtResults.Text = sw.ElapsedMilliseconds.ToString();
}
private void cmdInsert_Click(object sender, EventArgs e)
{
Stopwatch sw = new Stopwatch();
string cnStr = "Data Source=" + Server + ";Initial Catalog=" + Database + ";User Id=" + DBUser + "; Password=" + DBPass + ";";
string strSql = "Insert INTO dbo.SpeedTest (Mydata) VALUES ('Hello')";
sw.Start();
for (int i = 0; i < 10000; i++)
{
using (System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(cnStr))
{
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(strSql, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
}
sw.Stop();
this.txtResults.Text = sw.ElapsedMilliseconds.ToString();
}
|
|
|
|
|
Hi all,
How do you recursively remove the last character from a string in Oracle e.g for string 'HPN12345', I would like to build the following:
HPN12345
HPN1234
HPN123
HPN12
HPN1
HPN
I know how to do this in Oracle 11 using a recursive common table expression (CTE), but I need to implement this in Oracle 10g (without using a user function).
Thanks
|
|
|
|
|
A while loop based on the length would work.
|
|
|
|
|
Try this one... Change value of MIN_DEPTH and CHAR_STR as required.
SELECT SUBSTR(A.CHAR_STR, 0, LENGTH(A.CHAR_STR) - LEVEL + 1) OUTPUT
FROM (SELECT 'HPN12345' CHAR_STR, 3 MIN_DEPTH FROM DUAL) A
CONNECT BY LENGTH(A.CHAR_STR) - LEVEL + 1 >= A.MIN_DEPTH;
Thanks & Regards,
Niral Soni
|
|
|
|
|
Thanks Niral.. Your code was very helpful. It helped point me in the right direction.
Much appreciated!
|
|
|
|
|
i have installed windows application in sql server 2008,it has been installed but when
i click the icon in desktop error getting is [DBNETLIB][CONNECTION OPEN(connect()] SPECIFIED SQL SERVER NOT FOUND.How can i over come this error.
Ramesh
|
|
|
|
|
I doubt you have installed a windows application into SQL Server 2008.
Member 9999112 wrote: How can i over come this error.
By actually providing real information.
First this site is for the people who create applications not those who use them. So if you have an application that you got from somewhere then you need to go where you got it and ask there. This presumes of course that you already read all of the documentation that comes with the application.
But if this is an application that your wrote yourself then you need to provide some more detail about the code that is failing.
|
|
|
|
|
Hi All,
I am getting conversion error when i try to execute the following query... please help i need this scenario to be fixed for another business logic
Conversion failed when converting the varchar value '12r' to data type int.
declare @t table
(
val varchar(10)
)
insert into @t
select '1' union
select '2' union
select '3' union
select '4' union
select 'et' union
select '4' union
select '6' union
select '7' union
select '8' union
select '9' union
select '12r'
select * from @t where cast(val as int) > 3
|
|
|
|
|
12r cannot be converted because it is not a number.
Use the best guess
|
|
|
|
|
Try this:
select *
from @t
where
cast((case when isnumeric(val) = 1 then val else 0 end) as int) > 3
Edit -this will turn the 12r into a zero as it is not a valid integer.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
This question really does ask for a disparaging response.
If you can't work out that declaring a field of type int and trying to stuff text into it is going to fail and then cannot understand the very clear error message you should stop now and get an education.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Perhaps JavaScript could cast '12r' into an int with a value of 12, but many other programming/scripting languages won't do so.
|
|
|
|
|
Bernhard Hiller wrote: JavaScript could cast '12r' into an int
It does, how extraordinary, no wonder I loathe the script language.
There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: There is certain crappy banking software that will allow the traders to enter 12.65m or 328k as a trade values, WTF!
Considering how close K and M are on a qwerty keyboard
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Mycroft, I see original poster did not respond, but really curious - what does J-script convert '12r' to???
|
|
|
|
|
Richard.Berry100 wrote: what does J-script convert '12r' to???
Dammed if I know, as a Silverlight dev I don't have to get my hands grubby by rabbiting around in script languages.
The r probably stands for a currency sign, I image the conversion just drops the non numeric characters and turn the rest to an integer.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
SELECT
T1.ROW_ID,
T1.CREATED_BY,
T1.LAST_UPD_BY,
T1.NAME,
T1.PRTNR_FLG,
T1.CMPT_FLG,
T1.EMP_COUNT,
T1.BASE_CURCY_CD,
T1.CUST_STAT_CD,
T1.DOM_ULT_DUNS_NUM,
T1.DUNS_NUM,
T1.EAI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MP_ID,
--T6.DESC_TEXT as Primary_Industry_Category__c,
--T6.SIC as Primary_SIC_Code__c,
--T6.NAME as Primary_SIC_Description__c,
C.X_OFFICE_CODE,
C.X_REGION,
T1.PR_INDUST_ID
FROM
siebel.S_ORG_EXT T1,
siebel.S_ORG_EXT_X T4,
siebel.S_POSTN T5,
siebel.s_contact C--,
--siebel.S_INDUST T6
--
where
T1.X_CLIENT_TYPE is NOT NULL
and T1.CUST_STAT_CD in('Active','Inactive','Pending - Workflow Wizard')
AND C.EMP_FLG(+)='Y'
and T4.ROW_ID(+)=T1.ROW_ID
and T5.ROW_ID(+)=T1.PR_POSTN_ID
--and T6.ROW_ID(+)=T1.PR_INDUST_ID
and C.ROW_ID=T5.PR_EMP_ID
|
|
|
|
|
Here you go you can get forked[^]!
Seriously do you expect someone to rewrite your query for you! You do not state your database, from the joins I assume oracle but you have given absolutely zero information!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
There's nothing to rewrite. You select columns and join, that's it - it's as dressed down as it can get. If speed is an issue, consider partitioning your table and verifying the indexes.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Rearrange your WHERE clause as below -
WHERE C.ROW_ID = T5.PR_EMP_ID
AND T1.ROW_ID = T4.ROW_ID(+)
AND T1.PR_POSTN_ID = T5.ROW_ID(+)
AND C.EMP_FLG(+) = 'Y'
AND T1.CUST_STAT_CD IN ('Active','Inactive','Pending - Workflow Wizard')
AND T1.X_CLIENT_TYPE IS NOT NULL
Thanks & Regards,
Niral Soni
|
|
|
|
|
Hello,
Thanks in advance.
Table-1
startdate MSNUM
12/12/2012 1,2,3
12/10/2010 4
12/9/2009 5,6
12/13/2014
10/3/2003
Table-2
ID DESC
1 ONE
2 TWO
3 THREE
4 FOUR
5 FIVE
Expected OutPut Result
MSGNUM DESC
1,2,3 ONE,TWO,THREE
4 FOUR
5,6 FIVE,SIX
Note: Table-1 contains 7690 records and table-2 contains 160 fixed rows
Please let me know how can get the above output. I am trying using cursors still didn't found any solution. If anyone already worked on this can save my time.
best Regards,
Kumar
|
|
|
|
|
Because you have stored you MSNUM as a comma separated string (idiot) you are going to have to split the string. For this you need a split function that will return a table with the date and 1 ID per row. You then use this table to join you 2 existing tables.
This is the direct result of crappy design where someone is too bloody lazy to create the additional table to store the Date/MSNUM as discreet records.
There are plenty of examples around[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
 I am not sure what database you are using, but below is the query which resolves your problem and that works well in Oracle 11g.
SELECT MSGNUM, LISTAGG(DESCR, ',') WITHIN GROUP (ORDER BY LVL) AS MSGDESCR
FROM (SELECT DISTINCT MSGNUM, LEVEL LVL
,SUBSTR(NVL2(MSGNUM, MSGNUM || ',', NULL)
,(CASE WHEN LEVEL > 1 THEN
INSTR(NVL2(MSGNUM, MSGNUM || ',', NULL), ',', 1, LEVEL - 1) + 1
ELSE LEVEL END)
,INSTR(NVL2(MSGNUM, MSGNUM || ',', NULL), ',', 1, LEVEL)
- (CASE WHEN LEVEL > 1 THEN
INSTR(NVL2(MSGNUM, MSGNUM || ',', NULL), ',', 1, LEVEL - 1) + 1
ELSE LEVEL END)
) MSGNUM_TO_ID
FROM
(SELECT SYSDATE - 1 STARTDATE, '1,2,3' MSGNUM FROM DUAL UNION
SELECT SYSDATE - 2 STARTDATE, '4' MSGNUM FROM DUAL UNION
SELECT SYSDATE - 3 STARTDATE, '5,6' MSGNUM FROM DUAL UNION
SELECT SYSDATE - 4 STARTDATE, '' MSGNUM FROM DUAL UNION
SELECT SYSDATE - 5 STARTDATE, '4,2,5' MSGNUM FROM DUAL UNION
SELECT SYSDATE - 6 STARTDATE, '' MSGNUM FROM DUAL)
CONNECT BY INSTR(NVL2(MSGNUM, MSGNUM || ',', NULL), ',', 1, LEVEL) != 0
) T1
,(SELECT 1 ID, 'ONE' DESCR FROM DUAL UNION
SELECT 2 ID, 'TWO' DESCR FROM DUAL UNION
SELECT 3 ID, 'THREE' DESCR FROM DUAL UNION
SELECT 4 ID, 'FOUR' DESCR FROM DUAL UNION
SELECT 5 ID, 'FIVE' DESCR FROM DUAL UNION
SELECT 6 ID, 'SIX' DESCR FROM DUAL) T2
WHERE T1.MSGNUM_TO_ID = T2.ID
GROUP BY MSGNUM
;
Thanks & Regards,
Niral Soni
|
|
|
|
|