Showing posts with label adonet. Show all posts
Showing posts with label adonet. Show all posts

Tuesday, March 6, 2012

adodb.connection > DBMS Name property equivalent in ADO.NET ...

Hi,

One of my team member was porting a Visual Basic function into VB.NET. We were struck up while retrieving the DBMS Name property from the connection object. Actually in VB, the ADODB.connection object's properties will have an item called DBMS Name which will hold the database name like "Oracle" , "Access" , "SQL Server" like that based on the database that I connect.

I wonder if there is any equivalent property in ADO.NET. The Server Version property of ODBCConnection object returns "8.0...." in case of SQL Server and returns "09.01.0000 Oracle9i Enterprise Edition Release 9.2.0.1.0" in case of oracle. This is not as precise as it's ADODB counterpart.

I'm hardly in need of a solution or workaround for this scenario. Can anybody help.

Thanks in advance.

Hi Prathap,

The .Net Framework Data Access and Storage forum is the best forum with which to seek your answer (I see that you've already posted this question there).

Il-Sung.

Saturday, February 25, 2012

ADO.NET, SqlParameter, and NULL

Im trying to execute the following:

mySqlCmd.Parameters.Add("@.Parent_ID", SqlDbType.Int).Value = (sectionUpdate.iSection.ParentID == 0 ? DBNull.Value : myParentID);

However i get an error that Null cant be converted to Int. Is there any way i can uyse the SqlParameters approach but pass in a Null value for the field or must i wrap the entire connection within a IF/ELSE statement one containing a hard-coded NULL within the query and the other as a standard parameter with a proper int value?


Thanks

I found a solution:

SqlParameter sp = mySqlCmd.Parameters.Add("@.ParentID", SqlDbType.Int);
sp.IsNullable = true;

if (sectionUpdate.iSection.ParentID == 0)
sp.Value = DBNull.Value;
else
sp.Value = sectionUpdate.iSection.ParentID;

ADO.NET works, but data to/from database is truncated

I am using MSDE in a web application. The ADO.NET works, updating the
database correctly. The only thing is when I use the dataset, and when I
check the data in the database using server explorer the data is truncated. I
tried using the various ntext, nvarchar and setting the length to somthing
like a 100, but the data string is still to short somewhere. Only when this
comes to the dataset, and data in the database is this true. What can I do?
Thanks.
Spencer
hi Spencer,
Spencer H. Prue wrote:
> I am using MSDE in a web application. The ADO.NET works, updating the
> database correctly. The only thing is when I use the dataset, and
> when I check the data in the database using server explorer the data
> is truncated. I tried using the various ntext, nvarchar and setting
> the length to somthing like a 100, but the data string is still to
> short somewhere. Only when this comes to the dataset, and data in the
> database is this true. What can I do? Thanks.
did you manually set the datatype size?
check it's settings..
and probably you'll have better luck asking in the .Net heirarchy newsgroups
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.10.0 - DbaMgr ver 0.56.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||"Andrea Montanari" wrote:

> hi Spencer,
> Spencer H. Prue wrote:
> did you manually set the datatype size?
> check it's settings..
> and probably you'll have better luck asking in the .Net heirarchy newsgroups
> --
> Andrea Montanari (Microsoft MVP - SQL Server)
> http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
> DbaMgr2k ver 0.10.0 - DbaMgr ver 0.56.0
> (my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
> interface)
> -- remove DMO to reply
>
>
Did you say .NET hierarchy group. I couldn't find that group can you give me
the full name for the group?
|||microsoft.public.dotnet.framework.adonet
"Spencer H. Prue" <SpencerHPrue@.discussions.microsoft.com> wrote in message
news:5E484369-BCA3-4527-96A7-281CE91B01EE@.microsoft.com...
>
> "Andrea Montanari" wrote:
> Did you say .NET hierarchy group. I couldn't find that group can you give
> me
> the full name for the group?

ADO.NET Transaction Fails to update Database after .Commit()

SQL Server 2000, C#, ASP.NET and ADO.NET. I have searched for 3 days trying to figure out why my ADO.NET Transaction executes my stored procedures and runs the .COMMIT() on the server, figured this out by using the SQL Profiler, but the data doesn't show up in the database tables and I recieve no error from SQL or ASP.NET. What gives?? Anyone else ever heard of such a thing. Please help, before I loose my sanity.I may need to be more specific about the problem, so here goes. I am running an ADO.NET SQLTransaction that is calling 3 different stored procedures. The first proc Inserts data into a MailMessage Table and returns the @.@.IDENTITY of the Insert. The next set of stored procedures are called in a loop to Insert into a MailboxMessageAddressees table that has a foreign key of the MailMessages table and the ID of the Addressee. This loop can run 1-50+ times to insert all the Addressees. In SQL Profiler, I can trace the connection I made to a database and it starts the transaction, executes all stored procedures, and then COMMITS. I recieve no errors in my transaction and no errors occur on SQLServer. But the data is never inserted into the database. Its almost like the ADO.NET Transaction didn't take place, or SQL Server is rolling back the transaction on its own without throwing any errors that I can see.

Needless to say, I have closed the connection and disposed of the command and connection. Is there something else I need to send to SQL Server other than COMMIT to let it know that I have completed my transaction. This is really perplexing because I can manually execute all the stored procedures in Entrerprise Manager. I get every statement executed from the SQL Profiler when I trace the Transaction and put it in Query Analyzer and it works fine, and all the data shows up in SQL Server. Is there something I am missing?

Here is the actual code, maybe someone can clue me into what I might be missing.

/// <summary>
/// Mail_DAL.AddNewMessage(int Mailbox_ID,string subject,string body,ArrayList recipientTo,ArrayList recipientCc,ArrayList groupTo,ArrayList groupCc,ArrayList files,Wargame_ID)
/// ->Executes a ExecuteNonQuery using the Stored Procedure Mail_DeleteGroupAddressees and an ExecuteNonQuery using stored
/// procedure Mail_AddGroupAddressee to insert all addressees not in the Group.
/// </summary>
/// <param name="Mailbox_ID">Int: The Mailbox associated with the MailGroup.</param>
/// <param name="subject">String: The GroupName of the Group the addressees are associated with.</param>
/// <param name="body">String: The GroupName of the Group the addressees are associated with.</param>
/// <param name="recipientTo">ArrayList: An ArrayList of the To addresses Mailbox_IDs for the group.</param>
/// <param name="recipientCc">ArrayList: An ArrayList of the CC addresses Mailbox_IDs for the group.</param>
/// <param name="groupTo">ArrayList: An ArrayList of the To group addresses Mailbox_IDs for the group.</param>
/// <param name="groupCc">ArrayList: An ArrayList of the CC group addresses Mailbox_IDs for the group.</param>
/// <param name="files">ArrayList: An ArrayList of Files if there are any.</param>
/// <param name="Wargame_ID">Int: The Wargame_ID of any file to be put in Files</param>
public void AddNewMessage(int Mailbox_ID,string subject,string body,ArrayList recipientTo,ArrayList recipientCc,ArrayList groupTo,ArrayList groupCc,ArrayList files,int Wargame_ID)
{
//Get To Addresses from Groups
OpenProcCommand(Conn,"Mail_GetCurrentGroupAddressees");
SqlCommand cmd = ProcCommand;
param = new SqlParameter();
SqlDataReader dr;
Int32 holder = 0;
if(groupTo.Count > 0)
{
foreach(Object item in groupTo)
{
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.MailGroup_ID",SqlDbType.Int);
param.Value = item;
dr = cmd.ExecuteReader();
//Add any Group Recipients to Recipients ArrayList
while(dr.Read())
{
holder = Convert.ToInt32(dr["Mailbox_ID"].ToString());
if(!recipientTo.Contains(holder))
{
recipientTo.Add(holder);
}
}
dr.Close();
}
}

//Get CC Addresses from Groups
if(groupCc.Count > 0)
{
foreach(Object item in groupCc)
{
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.MailGroup_ID",SqlDbType.Int);
param.Value = item;
dr = cmd.ExecuteReader();
//Add any Group Recipients to Recipients ArrayList
while(dr.Read())
{
holder = Convert.ToInt32(dr["Mailbox_ID"].ToString());
if(!recipientCc.Contains(holder))
{
recipientCc.Add(holder);
}
}
dr.Close();
}
}

//Get BCC Recipients for this Maillbox
ArrayList recipientAll = new ArrayList();
recipientAll.Add(Convert.ToInt32(Mailbox_ID));
foreach(Object item in recipientTo)
{
recipientAll.Add(item);
}
foreach(Object item in recipientCc)
{
if(!recipientAll.Contains(item))
{
recipientAll.Add(item);
}
}
string allRecipients = "";
foreach(Object item in recipientAll)
{
allRecipients += item + ",";
}
allRecipients = allRecipients.Substring(0,allRecipients.Length-1);
ArrayList recipientBcc = new ArrayList();
cmd.CommandText = "Mail_GetBccAddressees";
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.Addressees",SqlDbType.VarChar,1000);
param.Value = allRecipients;
dr = cmd.ExecuteReader();
//Add any Bcc Recipients to Bcc Recipients ArrayList
while(dr.Read())
{
recipientBcc.Add(Convert.ToInt32(dr["Addressee"].ToString()));
}
dr.Close();

// Start a local transaction.
SqlTransaction myTrans = Conn.BeginTransaction();
// Enlist the command in the current transaction.
cmd.Transaction = myTrans;

try
{
//Insert Message into Database
cmd.CommandText = "Mail_AddNewMessage";
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.MsgFrom",SqlDbType.Int);
param.Value = Mailbox_ID;
param = cmd.Parameters.Add("@.MsgSubject",SqlDbType.VarChar,100);
param.Value = subject;
param = cmd.Parameters.Add("@.MsgBody",SqlDbType.Text);
param.Value = body;
int msg_ID = Convert.ToInt32(cmd.ExecuteScalar());

//Add To Recipients
cmd.CommandText = "Mail_AddMessageAddressees";
foreach(Object item in recipientTo)
{
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.Mailbox_ID",SqlDbType.Int);
param.Value = item;
param = cmd.Parameters.Add("@.Msg_ID",SqlDbType.Int);
param.Value = msg_ID;
param = cmd.Parameters.Add("@.MsgType_ID",SqlDbType.Int);
param.Value = 1;
cmd.ExecuteNonQuery();
}

//Add CC Recipients
foreach(Object item in recipientCc)
{
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.Mailbox_ID",SqlDbType.Int);
param.Value = item;
param = cmd.Parameters.Add("@.Msg_ID",SqlDbType.Int);
param.Value = msg_ID;
param = cmd.Parameters.Add("@.MsgType_ID",SqlDbType.Int);
param.Value = 2;
cmd.ExecuteNonQuery();
}

//Add BCC Recipients
foreach(Object item in recipientBcc)
{
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.Mailbox_ID",SqlDbType.Int);
param.Value = item;
param = cmd.Parameters.Add("@.Msg_ID",SqlDbType.Int);
param.Value = msg_ID;
param = cmd.Parameters.Add("@.MsgType_ID",SqlDbType.Int);
param.Value = 3;
cmd.ExecuteNonQuery();
}

//Add message to senders Mailbox in SentItems
cmd.Parameters.Clear();
param = cmd.Parameters.Add("@.Mailbox_ID",SqlDbType.Int);
param.Value = Mailbox_ID;
param = cmd.Parameters.Add("@.Msg_ID",SqlDbType.Int);
param.Value = msg_ID;
param = cmd.Parameters.Add("@.MsgType_ID",SqlDbType.Int);
param.Value = 4;
cmd.ExecuteNonQuery();

//Add files if there are any.
foreach(HttpPostedFile myfile in files)
{
//Get the file name
string FileName = myfile.FileName;
int strLoc = FileName.LastIndexOf("\\");
FileName = FileName.Remove(0,strLoc+1);

// Get size of uploaded file
int nFileLen = myfile.ContentLength;

// Allocate a buffer for reading of the file
byte[] myData = new byte[nFileLen];

// Read uploaded file from the Stream
myfile.InputStream.Read(myData, 0, nFileLen);
File file = new File();
int file_ID = file.UploadFile(cmd,3,FileName,nFileLen,myfile.GetType().ToString(),Wargame_ID,myData);

//Add the file message association
cmd.Parameters.Clear();
cmd.CommandText = "Mail_AddMessageFile";
param = cmd.Parameters.Add("@.Msg_ID",SqlDbType.Int);
param.Value = msg_ID;
param = cmd.Parameters.Add("@.File_ID",SqlDbType.Int);
param.Value = file_ID;
cmd.ExecuteNonQuery();
}
//Commit Transaction
myTrans.Commit();
}
catch (SqlException sqlex)
{
// Specific catch for deadlock
if (sqlex.Number != 1205)
{
myTrans.Rollback();
}
throw(sqlex);
}
catch(InvalidOperationException ex1){
string ex2 = ex1.ToString();
}
catch (Exception ex)
{
myTrans.Rollback();
throw (ex);
}
finally
{
myTrans.Dispose();
Conn.Close();
Conn.Dispose();
}

}|||First try to run a simple transaction with one stored proc and minimal .net code. This will make it easier to pinpoint your problem. Could be memory problem on server or some other potential problem you are not aware of.

This may not be a problem but I have encountered this one before. Are you returning more than one id with the @.@.IDENTITY call (i.e more than one insert command in a single transaction)? If you are you need to reset the sql connection or the same id is returned each time you call it if my memory serves me correctly.

Also, you can check the error status within a stored proc and return it to .net. I have used this before to pinpoint a problem.

Cheers

Mo|||Thanks Mo for the insight, unfortunatly I still have the same problems. Funny thing is I created a single stored procedure to do all the inserts, thinking that would solve the problem, but alas nothing. Getting different results, but same outcome. The database executes the procedure, which inserts data into the database, but for some reason after about 3 min or so the rows are rolled back. Running sp_lock I can see that the process that executed the command has a lock on all the tables, but it never gives them up. After that timeout, they are all rolled back. Is there some reason anyone can think of where this would happen. I can execute the stored procedure on the database using query analyzer and the data goes in fine and stays in there. Another thing to note, after the web application executes the stored procedure I cannot view the data in the tables through Enterprise manager. I can't even view the current activity, it sits there for a while then returns a 1222 Error. This has become a nightmare. Thanks

Chris|||Could be a bug between sql server and .net ?? Are both upto date with service packs?

Have you looked on http://support.microsoft.com

Very good area for problem solving, used it many times.

ADO.NET Timeout Exception - I have tried everything

Hello!
I am looking for someone who has solved this multi-million people's
problem. EVERYONE seems to ahve this problem.
Im a creating a data set and populating it with a call to a store proc.
Its a complex stored proc with the end result as an insert to a temp
table. Then I do a select from the temp table - in the store proc.
I get the following sqlException error on the following line:
DataAdapterName.Fill(DataSetName, "TableName")
The error is:
Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding.
My connectiong string looks like this:
<add key="cnITDevWinUser" value="Data Source=server; Integrated
Security=SSPI; Initial Catalog=dbname; pooling=false;connection
reset=false;connection lifetime=5;min pool size=1;max pool
size=10;connection timeout=120" />
I have admin rights on that db.
I have set my command.timeout to 500.
If i run this same code in a windows application, it works fine.
If I use a DataReader with the same storeProc, it works fine.
If I run this same code on a simple selec (hello world), it also works
fine.
If I run this store proc in QueryAnalyzer it works fine and is done
within 6 seconds.
If I run this on a different machine it produces the same result.
I am using SQL2000 with vb.net in VS2003.
I have looked everywhere for the answer. I can't find it anywhere.
PLEASE SOMEONE HELP.
regards,
Stas K.(a.k.a Sorcerdon)I had a similar problem as you. WHat I did was to was to insert the result
s
of the SP to a static table and then I read the contents of the static table
with the dataadapter.
Instead of retrieving data from the SP -- see if you can invoke the SP with
a command object from your client app and have the SP insert rows into a
static table. Then look at the table in Query Analyzer to see if you got an
y
rows. If you did not get any rows then you may have a connection problem.
If you did get rows, then I would retrieve data from the static table.
Rich
"sorcerdon@.gmail.com" wrote:

> Hello!
> I am looking for someone who has solved this multi-million people's
> problem. EVERYONE seems to ahve this problem.
> Im a creating a data set and populating it with a call to a store proc.
> Its a complex stored proc with the end result as an insert to a temp
> table. Then I do a select from the temp table - in the store proc.
>
> I get the following sqlException error on the following line:
> DataAdapterName.Fill(DataSetName, "TableName")
>
> The error is:
> Timeout expired. The timeout period elapsed prior to completion of the
> operation or the server is not responding.
>
> My connectiong string looks like this:
> <add key="cnITDevWinUser" value="Data Source=server; Integrated
> Security=SSPI; Initial Catalog=dbname; pooling=false;connection
> reset=false;connection lifetime=5;min pool size=1;max pool
> size=10;connection timeout=120" />
>
> I have admin rights on that db.
>
> I have set my command.timeout to 500.
>
> If i run this same code in a windows application, it works fine.
> If I use a DataReader with the same storeProc, it works fine.
> If I run this same code on a simple selec (hello world), it also works
> fine.
>
> If I run this store proc in QueryAnalyzer it works fine and is done
> within 6 seconds.
> If I run this on a different machine it produces the same result.
>
> I am using SQL2000 with vb.net in VS2003.
>
> I have looked everywhere for the answer. I can't find it anywhere.
> PLEASE SOMEONE HELP.
>
> regards,
> Stas K.(a.k.a Sorcerdon)
>

ADO.NET Timeout Exception - I have tried everything

Hello!
I am looking for someone who has solved this multi-million people's
problem. EVERYONE seems to ahve this problem.

Im a creating a data set and populating it with a call to a store proc.

Its a complex stored proc with the end result as an insert to a temp
table. Then I do a select from the temp table - in the store proc.

I get the following sqlException error on the following line:
DataAdapterName.Fill(DataSetName, "TableName")

The error is:
Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding.

My connectiong string looks like this:
<add key="cnITDevWinUser" value="Data Source=server; Integrated
Security=SSPI; Initial Catalog=dbname; pooling=false;connection
reset=false;connection lifetime=5;min pool size=1;max pool
size=10;connection timeout=120" /
I have admin rights on that db.

I have set my command.timeout to 500.

If i run this same code in a windows application, it works fine.
If I use a DataReader with the same storeProc, it works fine.
If I run this same code on a simple selec (hello world), it also works
fine.

If I run this store proc in QueryAnalyzer it works fine and is done
within 6 seconds.
If I run this on a different machine it produces the same result.

I am using SQL2000 with vb.net in VS2003.

I have looked everywhere for the answer. I can't find it anywhere.
PLEASE SOMEONE HELP.

regards,
Stas K.(a.k.a Sorcerdon)(sorcerdon@.gmail.com) writes:
> Im a creating a data set and populating it with a call to a store proc.
> Its a complex stored proc with the end result as an insert to a temp
> table. Then I do a select from the temp table - in the store proc.
>
> I get the following sqlException error on the following line:
> DataAdapterName.Fill(DataSetName, "TableName")
>
> The error is:
> Timeout expired. The timeout period elapsed prior to completion of the
> operation or the server is not responding.

How long time does take before you get the error? Since you say
that you've set the command timeout to 500, I expect it to take
three minutes, but I want to verify.

> If I use a DataReader with the same storeProc, it works fine.

Since DataAdapter.Fill more or less is just a wrapper on ExecuteReader,
this is funky. (Then again, that sounds like you have a workaround.)

I get the feeling that there is a blocking issue lurking here. When
you run DataAdapter.Fill and are waiting for it to timeout, run sp_who
from Query Analyzer and look for non-zero values in the Blk column.
In such case the spid in the Blk column blocks the spid on this row.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland,

Already done that. There are no locks.
I forgot to mention that in the original post.

regards,
Stas K (a.k.a Sorcerdon)|||Sorcerdon (sorcerdon@.gmail.com) writes:
> Already done that. There are no locks.
> I forgot to mention that in the original post.

I afraid then I don't have more suggestions with the information you have
given.

You could use Profiler to see if you get different query plans for
the different situations, althogh I don't see why that would happen.

Then again, there may be some pertinent information you have shared with
us.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||The problem is solved but a new mystery begins.
The problem was one of the parameters being passed is wrong.
but the mystery is that sql didnt return an error - it just froze...
intresting.

ADO.NET Timeout Exception - I have tried everything

Hello!
I am looking for someone who has solved this multi-million people's
problem. EVERYONE seems to ahve this problem.
Im a creating a data set and populating it with a call to a store proc.
Its a complex stored proc with the end result as an insert to a temp
table. Then I do a select from the temp table - in the store proc.
I get the following sqlException error on the following line:
DataAdapterName.Fill(DataSetName, "TableName")
The error is:
Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding.
My connectiong string looks like this:
<add key="cnITDevWinUser" value="Data Source=server; Integrated
Security=SSPI; Initial Catalog=dbname; pooling=false;connection
reset=false;connection lifetime=5;min pool size=1;max pool
size=10;connection timeout=120" />
I have admin rights on that db.
I have set my command.timeout to 500.
If i run this same code in a windows application, it works fine.
If I use a DataReader with the same storeProc, it works fine.
If I run this same code on a simple selec (hello world), it also works
fine.
If I run this store proc in QueryAnalyzer it works fine and is done
within 6 seconds.
If I run this on a different machine it produces the same result.
I am using SQL2000 with vb.net in VS2003.
I have looked everywhere for the answer. I can't find it anywhere.
PLEASE SOMEONE HELP.
regards,
Stas K.(a.k.a Sorcerdon)Another thought: Go to see the "SQL Server Logs" or the "Event Viewer" on th
e
Server machine to see if there is error occurred on hardware. Sometimes a
certain bad sector on disk can cause SQL Server timeout.
Just my 2 cents.
James
"sorcerdon@.gmail.com" wrote:

> Hello!
> I am looking for someone who has solved this multi-million people's
> problem. EVERYONE seems to ahve this problem.
> Im a creating a data set and populating it with a call to a store proc.
> Its a complex stored proc with the end result as an insert to a temp
> table. Then I do a select from the temp table - in the store proc.
>
> I get the following sqlException error on the following line:
> DataAdapterName.Fill(DataSetName, "TableName")
>
> The error is:
> Timeout expired. The timeout period elapsed prior to completion of the
> operation or the server is not responding.
>
> My connectiong string looks like this:
> <add key="cnITDevWinUser" value="Data Source=server; Integrated
> Security=SSPI; Initial Catalog=dbname; pooling=false;connection
> reset=false;connection lifetime=5;min pool size=1;max pool
> size=10;connection timeout=120" />
>
> I have admin rights on that db.
>
> I have set my command.timeout to 500.
>
> If i run this same code in a windows application, it works fine.
> If I use a DataReader with the same storeProc, it works fine.
> If I run this same code on a simple selec (hello world), it also works
> fine.
>
> If I run this store proc in QueryAnalyzer it works fine and is done
> within 6 seconds.
> If I run this on a different machine it produces the same result.
>
> I am using SQL2000 with vb.net in VS2003.
>
> I have looked everywhere for the answer. I can't find it anywhere.
> PLEASE SOMEONE HELP.
>
> regards,
> Stas K.(a.k.a Sorcerdon)
>|||Hi:
Check the memory usage/settings on the server. I encountered timeout
errors when the server ran out of memory on a complicated query that
was run repeatedly. Check the Event Log for 'Out of Memory' errors
(code 123, I believe).
- David
sorcerdon@.gmail.com wrote:
> Hello!
> I am looking for someone who has solved this multi-million people's
> problem. EVERYONE seems to ahve this problem.
> Im a creating a data set and populating it with a call to a store proc.
> Its a complex stored proc with the end result as an insert to a temp
> table. Then I do a select from the temp table - in the store proc.
>
> I get the following sqlException error on the following line:
> DataAdapterName.Fill(DataSetName, "TableName")
>
> The error is:
> Timeout expired. The timeout period elapsed prior to completion of the
> operation or the server is not responding.
>
> My connectiong string looks like this:
> <add key="cnITDevWinUser" value="Data Source=server; Integrated
> Security=SSPI; Initial Catalog=dbname; pooling=false;connection
> reset=false;connection lifetime=5;min pool size=1;max pool
> size=10;connection timeout=120" />
>
> I have admin rights on that db.
>
> I have set my command.timeout to 500.
>
> If i run this same code in a windows application, it works fine.
> If I use a DataReader with the same storeProc, it works fine.
> If I run this same code on a simple selec (hello world), it also works
> fine.
>
> If I run this store proc in QueryAnalyzer it works fine and is done
> within 6 seconds.
> If I run this on a different machine it produces the same result.
>
> I am using SQL2000 with vb.net in VS2003.
>
> I have looked everywhere for the answer. I can't find it anywhere.
> PLEASE SOMEONE HELP.
>
> regards,
> Stas K.(a.k.a Sorcerdon)|||Hi:
Check the memory usage/settings on the server. I encountered timeout
errors when the server ran out of memory on a complicated query that
was run repeatedly. Check the Event Log for 'Out of Memory' errors
(code 123, I believe).
- David
sorcerdon@.gmail.com wrote:
> Hello!
> I am looking for someone who has solved this multi-million people's
> problem. EVERYONE seems to ahve this problem.
> Im a creating a data set and populating it with a call to a store proc.
> Its a complex stored proc with the end result as an insert to a temp
> table. Then I do a select from the temp table - in the store proc.
>
> I get the following sqlException error on the following line:
> DataAdapterName.Fill(DataSetName, "TableName")
>
> The error is:
> Timeout expired. The timeout period elapsed prior to completion of the
> operation or the server is not responding.
>
> My connectiong string looks like this:
> <add key="cnITDevWinUser" value="Data Source=server; Integrated
> Security=SSPI; Initial Catalog=dbname; pooling=false;connection
> reset=false;connection lifetime=5;min pool size=1;max pool
> size=10;connection timeout=120" />
>
> I have admin rights on that db.
>
> I have set my command.timeout to 500.
>
> If i run this same code in a windows application, it works fine.
> If I use a DataReader with the same storeProc, it works fine.
> If I run this same code on a simple selec (hello world), it also works
> fine.
>
> If I run this store proc in QueryAnalyzer it works fine and is done
> within 6 seconds.
> If I run this on a different machine it produces the same result.
>
> I am using SQL2000 with vb.net in VS2003.
>
> I have looked everywhere for the answer. I can't find it anywhere.
> PLEASE SOMEONE HELP.
>
> regards,
> Stas K.(a.k.a Sorcerdon)

ADO.NET SP throws ArgumentException after migrating to SQL 2005 Standard - UPDATE 2 - FIXED

I just migrated a database from SQL 2000 Developer Edition on W2k Server to a production machine running SQL 2005 Standard on W2k3 Server Standard. A Web Service was also migrated from .NET 1.1 on the development machine to .NET 2.0 on the production machine.

Since the migration, a stored procedure that worked on SQL 2000/.NET 1.1 now throws a System.ArgumentException: "No mapping exists from object type System.RuntimeType to a known managed proider native type."

This occurs with a date value - the stored procedure is filled from XML data the Web Service receives from the client program by a generic subroutine that recognizes the applicable table names and primary key column names, selecting the appropriate stored procedure to use, but may or may not have data to update for each field. I have tried explicitly setting the SQLDBType for the parameter as the parametercollection is filled, but still get the ArgumentException. I also tried changing the parameter type to varchar(20), and having the stored procedure convert it to datetime, but still got the exception.

I know the ultimate solution will probably be to build the data Web Service within SQL 2005, but what can I do to get this working until I have time for that conversion?

Thanks for any help.

Darrell Escola

UPDATE - I was able to use the stored procedures to manually update the database using data that should have passed through the web service, so the problem is within the web service on .NET 2.0 - I think 2.0 is much stricter on data types than was 1.1. The SPs create dynamic SQL that is then executed - I know this is not the best security, hence my eventual interest in creating an end-point within SQL 2005 to handle the data in a more secure manner.

Darrell

|||

I finally got the web service to update through the stored procedure. I was able to access the stored procedure by specifically casting the data types for each parameter using a subroutine similar to that shown below, but the web service was still throwing an exception on the output value type, which I use to get the actual primary key value for the new record, so the off-line client can properly map its dependent records to the proper key value before inserting those dependent records:

Dim newID As SQLTypes.SQLInt32

I added a subroutine to determine the data type for each column used in the update:

Private Sub AddSPParameter(ByRef cmd as SQLClient.SQLCommand, ByVal paramName as String, ByVal fieldValue as Object)

If paramName = "<stringColName1>" Or paramName = "<stringColName...>" Then

cmd.Parameters.AddWithValue(Ctype(Cstr(fieldValue), SQLTypes.SQLString).DbType = DbType.String

ElseIf paramName = "<otherTypeColName1>" Or paramName.IndexOf("...") > 0 Or paramName.EndsWith("...") Then

cmd.Parameters.AddWithValue(Ctype(Cstr(fieldValue), SQLTypes.SQL<otherType>).DbType = DbType.<otherType>

ElseIf ...

End If

This subroutine determines the column data type by matches on the column name, and then explicitly casting the parameter value to the applicable database data type.

I also had to explicitly cast the Return Value:

cmd.Parameters.AddWithValue("@.ReturnValue", Ctype(0, SQLTypes.SQLInt32)).DbType = SqlDbType.Int

cmd.Parameters("@.ReturnValue").Direction = ParameterDirection.ReturnValue

Lesson learned: Explicitly type all data values used.

Darrell

ADO.NET SP throws ArgumentException after migrating to SQL 2005 Standard

I just migrated a database from SQL 2000 Developer Edition on W2k Server to a production machine running SQL 2005 Standard on W2k3 Server Standard. A Web Service was also migrated from .NET 1.1 on the development machine to .NET 2.0 on the production machine.

Since the migration, a stored procedure that worked on SQL 2000/.NET 1.1 now throws a System.ArgumentException: "No mapping exists from object type System.RuntimeType to a known managed proider native type."

This occurs with a date value - the stored procedure is filled from XML data the Web Service receives from the client program by a generic subroutine that recognizes the applicable table names and primary key column names, selecting the appropriate stored procedure to use, but may or may not have data to update for each field. I have tried explicitly setting the SQLDBType for the parameter as the parametercollection is filled, but still get the ArgumentException. I also tried changing the parameter type to varchar(20), and having the stored procedure convert it to datetime, but still got the exception.

I know the ultimate solution will probably be to build the data Web Service within SQL 2005, but what can I do to get this working until I have time for that conversion?

Thanks for any help.

Darrell Escola

UPDATE - I was able to use the stored procedures to manually update the database using data that should have passed through the web service, so the problem is within the web service on .NET 2.0 - I think 2.0 is much stricter on data types than was 1.1. The SPs create dynamic SQL that is then executed - I know this is not the best security, hence my eventual interest in creating an end-point within SQL 2005 to handle the data in a more secure manner.

Darrell

|||

I finally got the web service to update through the stored procedure. I was able to access the stored procedure by specifically casting the data types for each parameter using a subroutine similar to that shown below, but the web service was still throwing an exception on the output value type, which I use to get the actual primary key value for the new record, so the off-line client can properly map its dependent records to the proper key value before inserting those dependent records:

Dim newID As SQLTypes.SQLInt32

I added a subroutine to determine the data type for each column used in the update:

Private Sub AddSPParameter(ByRef cmd as SQLClient.SQLCommand, ByVal paramName as String, ByVal fieldValue as Object)

If paramName = "<stringColName1>" Or paramName = "<stringColName...>" Then

cmd.Parameters.AddWithValue(Ctype(Cstr(fieldValue), SQLTypes.SQLString).DbType = DbType.String

ElseIf paramName = "<otherTypeColName1>" Or paramName.IndexOf("...") > 0 Or paramName.EndsWith("...") Then

cmd.Parameters.AddWithValue(Ctype(Cstr(fieldValue), SQLTypes.SQL<otherType>).DbType = DbType.<otherType>

ElseIf ...

End If

This subroutine determines the column data type by matches on the column name, and then explicitly casting the parameter value to the applicable database data type.

I also had to explicitly cast the Return Value:

cmd.Parameters.AddWithValue("@.ReturnValue", Ctype(0, SQLTypes.SQLInt32)).DbType = SqlDbType.Int

cmd.Parameters("@.ReturnValue").Direction = ParameterDirection.ReturnValue

Lesson learned: Explicitly type all data values used.

Darrell

ADO.NET Source Custom Properties - Documentation Wrong?

Ok, so I've looked near and far and have found nothing but info that says data flow properties can not be changed at runtime....then I see in this in the SSIS documentation under ADO.NET Source Custom Properties:

SQLCommand

String

The SQL statement that the ADO.NET source uses to extract data.

The value of this property can be specified by using a property expression.


Pray tell me how this property can be specified using a property expression, or any other dts variable for that matter?
Thanks,
Adrian Crawford
Adrian,

You would never find this on your own, and I realize now that we need to document this more clearly in several places in BOL.

Property expressions for components within the Data Flow task are visible and available only on the containing Data Flow task itself at the present time. Select the Data Flow task on the Control Flow tab, or an empty spot on the Data Flow designer surface, go to the Properties window (it doesn't have a Properties dialog box), select Expressions, click the ellipsis, and in there you'll be able to drop down a list, select the SqlCommand property of your DataReader source, and set the expression.

Note that nothing will show up in the DataReader editor to indicate that you've set a value (with an expression) for the SqlCommand property...it will appear blank. I trust that the "usability" of this feature will be enhanced in the future. For now, however, it's better to have awkward access to data flow properties via property expressions, than none at all.

Best regards,

-Doug
|||Doug,
Thank you so much for your post. This is the holy grail I've been looking for, and I'll take it any way I can get it. It had boggled my mind because I had read rumors of this feature but was never able to make it work.
Thanks,
Adrian
|||Doug,

Do you know if Microsoft intends (in future revs) on allowing Web Service Task web-parameters to be updateable dynamically at runtime? Right now this one is killing me. I mean, who calls a web service with the same parameter every time?!?|||

Adrian,

Glad to hear it. I apologize for overlooking your earlier post on the same subject.

I've just finished updating and adding links to multiple BOL topics so that this not entirely intuitive how-to information will be easier to locate.

As I assume you've discovered, the Property list in the Property Expressions Editor only displays available properties for data flow objects that you've already placed on the Data Flow surface of the designer. (As a result, you can't use the Property list to view all the properties of data flow objects that support property expressions.) For example, if you've placed a DataReader Source on the designer surface, the Property list contains an entry for the [DataReader Source].[SqlCommand] property. The list also displays many properties of the Data Flow task itself.

Enjoy your expressions,

-Doug

|||I don't know the answer to that, but I understand why it would be useful. You can make your request known, as always, by using sqlwish@.microsoft.com and BetaPlace http://msdn.microsoft.com/sql/bugs/default.aspx.

Best regards,

-Doug
|||Just sent the request. I will feel so special if I, personally, effect the direction of Microsoft. :)

Just one more step in my eventual goal: Total global domination.|||A mere email to sqlwish may not achieve your entire goal, but Microsoft is more responsive to customer input than the average person gets to see. Especially the documentation team (have I mentioned those Feedback links in BOL?), where improving a BOL topic runs less risk of having unforeseen side-effects than code changes.|||Doug

I have the same problem as Adrian. I need to set the SQL Command of the Data Reader from a Variable. Trying your approach, the Property Drop Down List of the Property Expression Editor does not list an SqlCommand property.

What could be the problem?

Torsten|||Not many of the stock components implement expressions. There is a list in Books Online -

Using Property Expressions to Specify Data Flow Property Values
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/dtsref9/html/cd0e171a-08be-45d6-81dc-ed94f37698b8.htm

Seems like a reasonable request though so why not log it-
http://lab.msdn.microsoft.com/productfeedback/default.aspx|||If the ADO.Net source is in the dataflow, and you open the Expressions dialog for that dataflow, you should indeed find an entry in the properties drop down. It will likely be called "[DataReader Source].[SqlCommand]"

Thanks
Mark|||

I have a similar problem

want to use the property expression on data reader source

it loks like this

select @.var1, @.var2 from @.var3 inner join @.var4

where all the variables are from the foreachloop container > variable mapping

just tell me if this is correct

|||

You should be able to use aproperty expression (set it at the data flow level though, Expressions), but your syntax is not valid. Have a look at the BOL reference for the expression syntax. It should look more like this -

"SELECT " + @.var1 + ", " + @.var2 + " FROM " + @.var3 + " inner join " + @. var4 + " ON some columns!!!"

The evaluated expression result should give you a vali SQL statement that you could copy into any query tool and run, if not make it so that it can.

ADO.NET Source Custom Properties - Documentation Wrong?

Ok, so I've looked near and far and have found nothing but info that says data flow properties can not be changed at runtime....then I see in this in the SSIS documentation under ADO.NET Source Custom Properties:

SQLCommand

String

The SQL statement that the ADO.NET source uses to extract data.

The value of this property can be specified by using a property expression.


Pray tell me how this property can be specified using a property expression, or any other dts variable for that matter?
Thanks,
Adrian Crawford
Adrian,

You would never find this on your own, and I realize now that we need to document this more clearly in several places in BOL.

Property expressions for components within the Data Flow task are visible and available only on the containing Data Flow task itself at the present time. Select the Data Flow task on the Control Flow tab, or an empty spot on the Data Flow designer surface, go to the Properties window (it doesn't have a Properties dialog box), select Expressions, click the ellipsis, and in there you'll be able to drop down a list, select the SqlCommand property of your DataReader source, and set the expression.

Note that nothing will show up in the DataReader editor to indicate that you've set a value (with an expression) for the SqlCommand property...it will appear blank. I trust that the "usability" of this feature will be enhanced in the future. For now, however, it's better to have awkward access to data flow properties via property expressions, than none at all.

Best regards,

-Doug
|||Doug,
Thank you so much for your post. This is the holy grail I've been looking for, and I'll take it any way I can get it. It had boggled my mind because I had read rumors of this feature but was never able to make it work.
Thanks,
Adrian
|||Doug,

Do you know if Microsoft intends (in future revs) on allowing Web Service Task web-parameters to be updateable dynamically at runtime? Right now this one is killing me. I mean, who calls a web service with the same parameter every time?!?|||

Adrian,

Glad to hear it. I apologize for overlooking your earlier post on the same subject.

I've just finished updating and adding links to multiple BOL topics so that this not entirely intuitive how-to information will be easier to locate.

As I assume you've discovered, the Property list in the Property Expressions Editor only displays available properties for data flow objects that you've already placed on the Data Flow surface of the designer. (As a result, you can't use the Property list to view all the properties of data flow objects that support property expressions.) For example, if you've placed a DataReader Source on the designer surface, the Property list contains an entry for the [DataReader Source].[SqlCommand] property. The list also displays many properties of the Data Flow task itself.

Enjoy your expressions,

-Doug

|||I don't know the answer to that, but I understand why it would be useful. You can make your request known, as always, by using sqlwish@.microsoft.com and BetaPlace http://msdn.microsoft.com/sql/bugs/default.aspx.

Best regards,

-Doug
|||Just sent the request. I will feel so special if I, personally, effect the direction of Microsoft. :)

Just one more step in my eventual goal: Total global domination.|||A mere email to sqlwish may not achieve your entire goal, but Microsoft is more responsive to customer input than the average person gets to see. Especially the documentation team (have I mentioned those Feedback links in BOL?), where improving a BOL topic runs less risk of having unforeseen side-effects than code changes.|||Doug

I have the same problem as Adrian. I need to set the SQL Command of the Data Reader from a Variable. Trying your approach, the Property Drop Down List of the Property Expression Editor does not list an SqlCommand property.

What could be the problem?

Torsten|||Not many of the stock components implement expressions. There is a list in Books Online -

Using Property Expressions to Specify Data Flow Property Values
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/dtsref9/html/cd0e171a-08be-45d6-81dc-ed94f37698b8.htm

Seems like a reasonable request though so why not log it-
http://lab.msdn.microsoft.com/productfeedback/default.aspx|||If the ADO.Net source is in the dataflow, and you open the Expressions dialog for that dataflow, you should indeed find an entry in the properties drop down. It will likely be called "[DataReader Source].[SqlCommand]"

Thanks
Mark|||

I have a similar problem

want to use the property expression on data reader source

it loks like this

select @.var1, @.var2 from @.var3 inner join @.var4

where all the variables are from the foreachloop container > variable mapping

just tell me if this is correct

|||

You should be able to use aproperty expression (set it at the data flow level though, Expressions), but your syntax is not valid. Have a look at the BOL reference for the expression syntax. It should look more like this -

"SELECT " + @.var1 + ", " + @.var2 + " FROM " + @.var3 + " inner join " + @. var4 + " ON some columns!!!"

The evaluated expression result should give you a vali SQL statement that you could copy into any query tool and run, if not make it so that it can.

ADO.NET returns different colum value when compared to View results in SQL 2005 Management

I have a complex view in my sql 2005 database.

The view returns a column that could be null (as the result of a left outer join).

The coulmn that is returned is an integer.

Everything works fine if I run the view from SQL 2005 Management Studio.

My column value is always null if I use ADO.NET's SqlAdapter to return a DataTable.

Has anybody seen this behaviour before?

Any help appreciated.

Regards,

Paul.

Hi Paul,

From you description, I understand that when you query data from the database view, the destination column in the DataSet is always null.

This could be caused by a wrongly configured SqlDataAdapter or the mismatched target DataSet schema.

For example, if you're using a typed DataSet, the target column data type is in another type. In this case, data might be converted incorrectly. Also, please try to check the table mapping and column mapping for the SqlDataAdapter.

HTH.

|||

I've solved the problemSmile

I changed the DB Connection to system admin and everything worked ok.

Looks like I've got a permissions issue with one or more of my SQL Functions.

Thanks for the help.

Regards,

Paul.

ADO.NET problem?

I'm experiencing a strange problem that I believe is related to ADO.NET
but I can't say for sure.

I have a simple ASP.NET reporting interface to a SQL Server 2000
database. One report that we run returns a listing of community
members and their contact information using a stored procedure.
Depending on the selected community, this can return from a hundred to
over 1000 rows. Occasionally, the report stops running when a
community with large membership is run -- the report hangs for a while
and then comes back empty (no dataset). If I try to run the stored
procedure directly with the same parameters, everything seems perfectly
fine. I can temporarily fix the problem by simply running an ALTER
PROCEDURE statement without making a single change to the procedure.
The report will now run fine for several days until it eventually stops
again.

I can't reproduce the problem in my development environment.

Does anyone have any ideas as to what this could be?

Bill E.
Hollywood, FL(billmiami2@.netscape.net) writes:

Quote:

Originally Posted by

I'm experiencing a strange problem that I believe is related to ADO.NET
but I can't say for sure.
>
I have a simple ASP.NET reporting interface to a SQL Server 2000
database. One report that we run returns a listing of community
members and their contact information using a stored procedure.
Depending on the selected community, this can return from a hundred to
over 1000 rows. Occasionally, the report stops running when a
community with large membership is run -- the report hangs for a while
and then comes back empty (no dataset). If I try to run the stored
procedure directly with the same parameters, everything seems perfectly
fine. I can temporarily fix the problem by simply running an ALTER
PROCEDURE statement without making a single change to the procedure.
The report will now run fine for several days until it eventually stops
again.
>
I can't reproduce the problem in my development environment.


It sounds that you run into a command timeout, and the error message
is then thrown away.

I assume that when you run the procedure directly afterwards, that you
are running it from Query Analyzer.

Next time this happens, before you run the procedure in Query Analyzer,
issue this command:

SET ARITHABORT OFF

My prediction is that it will now run as slow as it did ASP .Net.

As you may know SQL Server creates a query plan for a stored procedure
when you run it the first time, and this plan is put into cache.

Now, there can be more than one plan for the same procedure, because
of the different set options. For a discussion on this see
http://www.karaszi.com/SQLServer/in...compile_set.asp.

All modern client APIs uses the same SET options by default. Query
Analyzer uses a different default on one point: it runs with SET
ARITHABORT ON, which a client API does not.

Therefore when you run the procedure from QA, you will get a different
plan than you did for the ASP .Net client.

Next phenomenon is something called "parameter sniffing". When SQL Server
creates the query plan for a stored procedures, it looks at the input
parameter for the first invocation. My guess is that the weh page runs with
a plan that is good for a small selection. Typically there will be no
plan in cache which matches the settings for QA, so you will get a plan
which is better fit for the larger selection.

Note here that this does not say that things will faster if ARITHABORT
is ON. Had the defaults been in the reverse, you would have seen the
same behaviour. (With one qualification: ARITHABORT must be ON for
indexes on computed columns and views to be used, so if such are involved
it can make a lot of difference.)

Exactly what is the best resolution for your situation is difficult to
say with the amount of information given. If you can live with the slow
response time on large selections, set the CommandTimeout on the Connection
object to 0, to prevent timeouts from happenning. (There was a bug in
earlier versions of SqlClient where 0 was interpreted as 0. If you have an
old version of .Net Fx 1.x, you may have to set the command timeout to 32767
instead.)

If that is not feasible you may have to review indexing and also examine
the query plan in more detail.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland,

Thanks for the response as always.

I'll try the SET ARITHABORT OFF in query analyzer the next time it
occurs. I would be very interested to see what happens in this case.

When it's working, the query runs very quickly, even when 1000 rows are
returned. This is true for both query analyzer and the web page. Of
course when it breaks down, the web page stops but query analyzer still
runs it in a split second.

I certainly know that SQL Server creates an execution plan on the first
run, but I never thought that there would be two execution plans and
certainly not a different one for a large resultset vs. a small
resultset.

The query contains a large number of subqueries which I think might be
confusing the optimizer. Perhaps a solution using some temp tables
will help--I'll have to see.

No, setting the timeout longer won't suffice, especially when I know
that the query has the potential to run quickly.

Bill

Erland Sommarskog wrote:

Quote:

Originally Posted by

(billmiami2@.netscape.net) writes:

Quote:

Originally Posted by

I'm experiencing a strange problem that I believe is related to ADO.NET
but I can't say for sure.

I have a simple ASP.NET reporting interface to a SQL Server 2000
database. One report that we run returns a listing of community
members and their contact information using a stored procedure.
Depending on the selected community, this can return from a hundred to
over 1000 rows. Occasionally, the report stops running when a
community with large membership is run -- the report hangs for a while
and then comes back empty (no dataset). If I try to run the stored
procedure directly with the same parameters, everything seems perfectly
fine. I can temporarily fix the problem by simply running an ALTER
PROCEDURE statement without making a single change to the procedure.
The report will now run fine for several days until it eventually stops
again.

I can't reproduce the problem in my development environment.


>
It sounds that you run into a command timeout, and the error message
is then thrown away.
>
I assume that when you run the procedure directly afterwards, that you
are running it from Query Analyzer.
>
Next time this happens, before you run the procedure in Query Analyzer,
issue this command:
>
SET ARITHABORT OFF
>
My prediction is that it will now run as slow as it did ASP .Net.
>
As you may know SQL Server creates a query plan for a stored procedure
when you run it the first time, and this plan is put into cache.
>
Now, there can be more than one plan for the same procedure, because
of the different set options. For a discussion on this see
http://www.karaszi.com/SQLServer/in...compile_set.asp.
>
All modern client APIs uses the same SET options by default. Query
Analyzer uses a different default on one point: it runs with SET
ARITHABORT ON, which a client API does not.
>
Therefore when you run the procedure from QA, you will get a different
plan than you did for the ASP .Net client.
>
Next phenomenon is something called "parameter sniffing". When SQL Server
creates the query plan for a stored procedures, it looks at the input
parameter for the first invocation. My guess is that the weh page runs with
a plan that is good for a small selection. Typically there will be no
plan in cache which matches the settings for QA, so you will get a plan
which is better fit for the larger selection.
>
Note here that this does not say that things will faster if ARITHABORT
is ON. Had the defaults been in the reverse, you would have seen the
same behaviour. (With one qualification: ARITHABORT must be ON for
indexes on computed columns and views to be used, so if such are involved
it can make a lot of difference.)
>
Exactly what is the best resolution for your situation is difficult to
say with the amount of information given. If you can live with the slow
response time on large selections, set the CommandTimeout on the Connection
object to 0, to prevent timeouts from happenning. (There was a bug in
earlier versions of SqlClient where 0 was interpreted as 0. If you have an
old version of .Net Fx 1.x, you may have to set the command timeout to 32767
instead.)
>
If that is not feasible you may have to review indexing and also examine
the query plan in more detail.
>
--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
>
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

|||(billmiami2@.netscape.net) writes:

Quote:

Originally Posted by

When it's working, the query runs very quickly, even when 1000 rows are
returned. This is true for both query analyzer and the web page. Of
course when it breaks down, the web page stops but query analyzer still
runs it in a split second.
>
I certainly know that SQL Server creates an execution plan on the first
run, but I never thought that there would be two execution plans and
certainly not a different one for a large resultset vs. a small
resultset.


When I said that there could be different plans for large and small result
sets that was a simplification. Consider this simple procedure:

CREATE PROCEDURE get_count @.val int, @.count OUTPUT AS
SELECT @.count = count(DISTINCT col1) FROM tbl WHERE col2 = @.val

Assume that here is a non-clustered index on col2 and that this index
does not include col1, nor is col1 in the clustred index. Assume further
that the distribution of col2 is uneven. 30% of the rows have 0 in this
column, the remaining rows have scattered value.

If the first invocation is for @.val = 10, the optimizer will use the
index to compute the query. But if the first invocation is for @.val = 0,
the optimizer will scan the table, because that is faster in this case.

Now, exactly what is going in your application I don't know. But it
sounds as if the procedure is recompiled at some point, and the input
values at that point are very atypical, leading to a poor execution plan
for regular values. That poor plan could affect smaller selection, but
you could be lucky that the cost is less noticeable in this case.

But why would the procedure be recompiled? There are several reasons
for this. One is change in statistics. By default SQL Server maintains
statistics on the tables, and when they change for a table, referring
procedures will be recompiled. It could also be that the plan falls out
of cache if there is memory pressure, and the procedure has not been
used for a while.

One thing you could consider is to add WITH RECOMPILE to the procedure
definition. In this case the procedure is recompiled each time it is
invoked, and nothing is put into cache. The recompile has a cost, but
at least you prevent a bad plan from sticking.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Erland,

This occurred again so I immediately tried the SET ARITHABORT OFF
option and you were correct--the query ran slowly in query analyzer as
well.

By the way, we discovered that this problem is occurring not only with
the member listing procedure but also a member search procedure when an
address search option is selected. Other search options do not cause
problems. Therefore, I am beginning to suspect that something is wrong
with our address table. Perhaps we have some fragmentation in an index
or something related. In the interim, I've added the WITH RECOMPILE
clause to these two procedures to ensure that they do not run slowly or
time out. Fortunately, this doesn't appear to be slowing them down
much.

Bill|||(billmiami2@.netscape.net) writes:

Quote:

Originally Posted by

By the way, we discovered that this problem is occurring not only with
the member listing procedure but also a member search procedure when an
address search option is selected. Other search options do not cause
problems. Therefore, I am beginning to suspect that something is wrong
with our address table. Perhaps we have some fragmentation in an index
or something related.


You can examine fragmentation with DBCC SHOWCONTIG. But I would not expect
that to be the problem, since you apparently get different plans.

But statistics may not be current. By default, SQL Server updates statistics
automatically, but for large tables it may not be often enough.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||I'll take a look.

The table isn't large. It only has about 15,000 rows.

Bill

ADO.NET Please Help ?

ADO.NET is great But I have a problem

I using Stored Procedures and UDFs to Insert and retrieve my data

I can recieve a variable Only from UDF or Stored Procedure

Put when the returned value is a set of records Whats the matter then ?

and very especially: I need to know How to navigate through this set of records Next,Previous,First and Last Programmatically without Binding to Controls

One of my Friends challenge me and Say :"Go and use Recordset as usual"

But I Persist on my opinion that ADO.NET is moore efficient !!!

But next Previous problem STOPS me

Please any help from any of you

sites links,material or code inVB if available please ..

Thanks for All

Many Thanks to Microsoft

I'm really lost as to what your problem is. If you get a dataset back from a stored proc, you can use for each to iterate through the rows, or if you want a prev/next/first/last paradigm, you can reference them by index.

|||

Thanks

But can you provide me with any example on how toreference them by index in Any Language please if you can

And Really Is The ADO.NET more efficient than Recordset ?

(To Speak to my friend)

Sorry for my bad english

thanks

|||

To be honest, ADO.NET is your only option in ASP.NET afaik.

DataSet dataSet = new DataSet();

SqlConnection connection = createConnection(true);

try

{

sqlCommand.Connection = connection;

SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlCommand);

dataAdapter.Fill(dataSet);

return dataSet;

}

finally

{

connection.Close();

}

Would be an example of getting a dataset back from the database.

I believe that dataSet.Rows[0] would be an example of grabbing a row by index, and dataSet.Rows.Count would tell you how many rows there are.

|||

thanks more sir

But Can I speak to you online

this is my msn :moh_omar52@.hotmail.com

I have little bit questions

If you can not O.K

Thnaks in all conditions

Mohamed Omar

|||

I would definately prefer that you ask further questions on this forum, so that others can help you if they have a better answer than me, and other users can benefit from my replies.

|||

O.K

To be honest, ADO.NET is your only option in ASP.NET afaik.

Really I do not understand this ?(Sorry)

and you speak about ADO.NET 2.0 ( I think that It has great improvments ?)

I mean that there is no implementations in .NET 2.0 that allow to me directly access the Last Or Next Records

Does Really Microsoft puts 70% of its resources to .NET ?

I am sorry If you are annoyed from me !!

|||

I'm not annoyed, if I was, I would stop answering :-)

ADO.NET is the database model for ASP.NET. If you want to use another model, it's not built in, you'd have to do a lot of work to use an inferior model ( inferior because ADO.NET, as a disconnected model, is perfect for web development ).

ADO.NET 2.0 has a lot of new stuff, I've not seen anything I consider an 'improvement' though.

No, you cannot directly access the last nor next records from the DB, because you download ALL The records from your query when you make it. You don't maintain a connection, so the iteration happens entirely in your code, not through a database connection. My code sample shows how to use the dataset you get from the database to step through records if you need to.

I have no idea of percentages, but yes, Microsoft obviously is pushing .NET significantly over and above other options (the only other option being VC++, VB6 is completely unsupported now ).

|||

OK.

my Final Questions

Do you See that .NET will be the future of development especially when Vista ships and in the coming 10 Years ?

If I to be obliged to call a Windows API OR Use Unmanaged dll from the .NET World,

Do you think that this will affect my application performance ? %

I really happy with all these answers and Thank you More

|||

I don't see .NET going anywhere. .NET is not fundamental to Vista ( that is, I don't believe Vista uses it ), but Vista is not going to kill it either, they coexist, but are not codependant. I don't know if I will be using C# in 10 years time, but I don't care. Today, it's a good option. I still use C++, and will move back to it if that's what a project needs, or if the world turns back that way. I doubt it though. New languages will pop up from time to time. WPF is a new framework, they will pop up as well. As a developer, you can expect to always be learning and using new things.

If you call a native API, it's possible that things will work faster :-)

Glad to help...

|||

Hi my friend

sorry When I spoke to you yesterday I do not test any code BUt

this propety is not found in the dataset

dataSet.Rows[0]

Is not found ?

|||

dataSet.Tables(0).Rows(0), or dataSet.Tables[0].Rows[0] ( first VB, then C# )

The dataset has a collection of tables, each table has a collection of rows.

ADO.NET parameterized query security

I am developing a website for multiple clients, each with their own separate database on SQL Server 2005. The database structures are identical for all clients. I like to use SQL stored procedures for the security advantages (i.e., don't need to grant access to the tables, only exec permissions on the stored procedures), but maintaining and deploying many sp's across all databases is becoming unwieldy and error-prone.

Is there a way to use parameterized queries (SqlCommand, SqlParameter) in C# code (which could be reused for all databases by changing the connection string) without having to grant access to the tables?

From your description, you are relying on ownership chaining to access tables only from SPs; this is possible only because the SP owner is the same as the underlying tables and the security checks are bypassed; but sqlcommand will not be able to use any chaining directly.

In any case, we would like to understand your needs in order to give better advice as well as to understand our customer needs. For example, is the reason behind not granting permissions directly on the table to protect from ad-hoc queries, or to help in managing permissions? If it is for managing permissions, what may be the obstacle from using the existing permission model?

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||


You don′t need to grant permissions on the tables as long as the owner of the tables are the same as those for the stored procedure. This is called owner ship chaining, there is more to read about that in the BOL. Don′t breaking the ownership chain means that the permission is checked once at the procedure level. SQL Server assumes then lateron during the access of the table that if the grantee has access to the proc and the grantor created the stored procedure accessing the base tables th grantor also wanted the grantee to access the base tables. Permissions are not checked twice then. If the ownership chain is broken (Another owner of the base tables than the stored procedure) permissions are checked for every underlying base object. Using SQL Server 2005 you can also use impersonation within your stored procedures, acessing data / base tables using the WiTH EXECUTE AS syntax.

Jens K. Suessmeyer


http://www.sqlserver2005.de|||

Thank you all for your quick response and comments!

The reason to avoid granting access directly on the tables is to protect from ad-hoc queries, if an unauthorized user gains access through the login used by the website. To minimize the damage if that were to happen, we want this login to have only minimal rights to the database.

From a wider perspective, I normally prefer using stored procedures, but sometimes we need the flexibility of building a parameterized query in the Web application. I would like to find a way of doing that without giving up the security advantage of using stored procedures. What is the best way to accomplish this?

|||

I would recommend following Jens’ suggestion and use either EXECUTE AS (or digital signatures) in order to change the execution context before accessing the tables. Here are a few good starting points in BOL for this topic:

· Context switching (http://msdn2.microsoft.com/en-us/library/ms188268.aspx)

· Module signing (http://msdn2.microsoft.com/en-us/library/ms345102.aspx)

If you decide to use this mechanism, I would also like to strongly recommend following the least privilege principle. For example, if for this application the application (impersonated) context only needs to have SELECT on a couple of tables, make sure that the permissions are limited only to the proper tables.

I hope this information helps,

-Raul Garcia

SDE/T

SQL Server Engine

Friday, February 24, 2012

ADO.net or TSQL Transactions

Hi all
Should implement a transaction in both the stored procedure AND in ADO.net
code or is doing it in one or the other good enough to protect against
concurrency and atomicity problems?
Thanks
Simon
"Mary Chipman" <mchip@.online.microsoft.com> wrote in message
news:8egpp052lm2jkkuv2e5dik0k1h4pvgncc4@.
4ax.com...
> If you have complex explicit transactions, your best bet is going to
> be to implement them in your stored procedure(s) in T-SQL both in
> terms of performance and simplicity. Implementing them in client code
> may cause more round trips and not be as performant. Call a single
> stored procedure that executes the transactions and returns
> success/failure information in output parameters. See the BEGIN
> TRANSACTION and related topics in SQL Books Online for more
> information.
> --Mary
> On Thu, 18 Nov 2004 09:48:47 -0000, "Simon Harvey"
> <sh856531@.microsofts_free_email_service.com> wrote:
>
>Simon Harvey wrote:[vbcol=seagreen]
> Hi all
> Should implement a transaction in both the stored procedure AND in
> ADO.net code or is doing it in one or the other good enough to
> protect against concurrency and atomicity problems?
> Thanks
> Simon
> "Mary Chipman" <mchip@.online.microsoft.com> wrote in message
> news:8egpp052lm2jkkuv2e5dik0k1h4pvgncc4@.
4ax.com...
If you're talking about SQL running from a client as opposed to running
a single stored procedure, I think you have to go the SP route (in most
cases). Security aside, imagine running 20 SQL commands from a client on
the server in succession: each one requires a full round-trip to the
server which can slow things down. OTOH, a single SP is a single call.
While the slower client-side transaction runs, it holds locks on the
server, which in turn causes other transactions to wait on locked
resources which slows everyone down.
Plus, if you have to make an implementation change, you don't have to
deal with recompiling the app and distributing it to everyone.
David Gugick
Imceda Software
www.imceda.com|||A transaction has to be ATOMIC regardless of who starts it otherwise what
good is it. So two transactions are not better than one in this case. If
the outer one is Rolled back then ALL the nested ones are too. Sometimes it
makes sense to have trans in sp's so that if you call the sp by itself
everything inside it is all or nothing. But if you begin a tran from
outside a sp, everything from there on will be wrapped in that same tran.
Andrew J. Kelly SQL MVP
"Simon Harvey" <sh856531@.microsofts_free_email_service.com> wrote in message
news:eOl8GlkzEHA.1204@.TK2MSFTNGP10.phx.gbl...
> Hi all
> Should implement a transaction in both the stored procedure AND in ADO.net
> code or is doing it in one or the other good enough to protect against
> concurrency and atomicity problems?
> Thanks
> Simon
> "Mary Chipman" <mchip@.online.microsoft.com> wrote in message
> news:8egpp052lm2jkkuv2e5dik0k1h4pvgncc4@.
4ax.com...
>|||Except that sometimes you need to do something and then do more things in
source code that depend on that something and so on. Unless you move your
entire application into the SP, you'll have no choice but to wrap the
transaction into an ADO.NET call. Apart from the fact that (in our case) it
may not be feasible to rewrite 2.5 million lines of code to accomodate SP
only transactions, not to mention that some of the older parts of the code
(that are being rewritten into .NET) use embedded SQL...
You'll just have to evaluate your application architecture if it already
exists, or decide how you will be accessing the data at all times in your
application of you are currently designing it. There's a time and place for
everything. But know this, if you begin a transaction in the SP and for
some reason need to execute source code that may depending on something from
a currently running transaction, and it attempts to start a transaction and
call an SP that starts its own transaction, you'll get an exception. So you
either do it one way or another but not both, unless you want to excercise
your patients and stamina.
Thanks,
Shawn
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:ut0iiRlzEHA.824@.TK2MSFTNGP11.phx.gbl...
> Simon Harvey wrote:
> If you're talking about SQL running from a client as opposed to running
> a single stored procedure, I think you have to go the SP route (in most
> cases). Security aside, imagine running 20 SQL commands from a client on
> the server in succession: each one requires a full round-trip to the
> server which can slow things down. OTOH, a single SP is a single call.
> While the slower client-side transaction runs, it holds locks on the
> server, which in turn causes other transactions to wait on locked
> resources which slows everyone down.
> Plus, if you have to make an implementation change, you don't have to
> deal with recompiling the app and distributing it to everyone.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>|||Shawn B. wrote:
> Except that sometimes you need to do something and then do more
> things in source code that depend on that something and so on.
> Unless you move your entire application into the SP, you'll have no
> choice but to wrap the transaction into an ADO.NET call. Apart from
> the fact that (in our case) it may not be feasible to rewrite 2.5
> million lines of code to accomodate SP only transactions, not to
> mention that some of the older parts of the code (that are being
> rewritten into .NET) use embedded SQL...
> You'll just have to evaluate your application architecture if it
> already exists, or decide how you will be accessing the data at all
> times in your application of you are currently designing it. There's
> a time and place for everything. But know this, if you begin a
> transaction in the SP and for some reason need to execute source code
> that may depending on something from a currently running transaction,
> and it attempts to start a transaction and call an SP that starts its
> own transaction, you'll get an exception. So you either do it one
> way or another but not both, unless you want to excercise your
> patients and stamina.
>
> Thanks,
> Shawn
I thought the OP asked a simple question: Which is better to use in an
application SPs or embedeed SQL. The answer to _that_ simple question is
stored procedures. But that's not the question he asked. He asked
whether the transaction should be started in the app or on in the SP. I
think Andrew answered that question. But I stand by answer to a question
that was never asked :-)
David Gugick
Imceda Software
www.imceda.com|||I think the relevance, while not as direct as previous answers, is that "it
depends on how your code and workflow is organized". I'm not dissagreeing
with the "simple" answer, that you use transactions in the SP. However,
I've rarely encountered a business application that was designed in such a
way that all transactions were at the SP level. I was only offering a
difference perspective, a difference way of looking at things, another thing
to take into consideration. Nothing more.
Thanks,
Shawn
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:u4zdwPmzEHA.3336@.TK2MSFTNGP11.phx.gbl...
> Shawn B. wrote:
>
> I thought the OP asked a simple question: Which is better to use in an
> application SPs or embedeed SQL. The answer to _that_ simple question is
> stored procedures. But that's not the question he asked. He asked
> whether the transaction should be started in the app or on in the SP. I
> think Andrew answered that question. But I stand by answer to a question
> that was never asked :-)
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>|||Shawn B. wrote:
> I think the relevance, while not as direct as previous answers, is
> that "it depends on how your code and workflow is organized". I'm
> not dissagreeing with the "simple" answer, that you use transactions
> in the SP. However, I've rarely encountered a business application
> that was designed in such a way that all transactions were at the SP
> level. I was only offering a difference perspective, a difference
> way of looking at things, another thing to take into consideration.
> Nothing more.
>
> Thanks,
> Shawn
>
I agree with you Shawn. Unless you have strict standards (which are not
bad to have), most applications will have some embedded SQL, even if
using SPs is the standard. Although, I'm not sure if you have an SP
standard for an app that ending up with a mixed code base is good from a
maintenance and security standpoint. It's nice to know no one can access
your database, except through stored procs.
David Gugick
Imceda Software
www.imceda.com|||Hi all,
Thanks for your answers so far.
I'm still not sure about something. Are ADO.net transactions and TSQL
transactions essentially equivelent?
If I do a big stored procedure, locked through ADO.net, will all the the
rows be locked until the SP returns?
I'm worried that if I use ADO, the stored procedure still might cause a
concurrency problem. This is essentially my problem.
Thanks again
Simon|||Simon,
An ADO transaction (.net or otherwise) is nothing more than passing a BEGIN
TRAN to SQL Server. So it's always a SQL Server transaction and any rows
locked after the first Begin Tran is issued (regardless of where or by who)
on that connection will remain locked until the final commit (if nested) or
the first Rollback.
Andrew J. Kelly SQL MVP
"Simon" <sh856531@.microsofts_free_email_service.com> wrote in message
news:%23GAkzXyzEHA.3336@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> Thanks for your answers so far.
> I'm still not sure about something. Are ADO.net transactions and TSQL
> transactions essentially equivelent?
> If I do a big stored procedure, locked through ADO.net, will all the the
> rows be locked until the SP returns?
> I'm worried that if I use ADO, the stored procedure still might cause a
> concurrency problem. This is essentially my problem.
> Thanks again
> Simon
>|||Andrew J. Kelly wrote:
> Simon,
> An ADO transaction (.net or otherwise) is nothing more than passing a
> BEGIN TRAN to SQL Server. So it's always a SQL Server transaction
> and any rows locked after the first Begin Tran is issued (regardless
> of where or by who) on that connection will remain locked until the
> final commit (if nested) or the first Rollback.
>
I would add that if concurrency is a concern, letting SQL Server start
and end the transaction from within the SP will be faster than doing so
from .net because it will eliminate 2 additional round-trips to the
server.
David Gugick
Imceda Software
www.imceda.com

ADO.net or TSQL Transactions

Hi all
Should implement a transaction in both the stored procedure AND in ADO.net
code or is doing it in one or the other good enough to protect against
concurrency and atomicity problems?
Thanks
Simon
"Mary Chipman" <mchip@.online.microsoft.com> wrote in message
news:8egpp052lm2jkkuv2e5dik0k1h4pvgncc4@.4ax.com...
> If you have complex explicit transactions, your best bet is going to
> be to implement them in your stored procedure(s) in T-SQL both in
> terms of performance and simplicity. Implementing them in client code
> may cause more round trips and not be as performant. Call a single
> stored procedure that executes the transactions and returns
> success/failure information in output parameters. See the BEGIN
> TRANSACTION and related topics in SQL Books Online for more
> information.
> --Mary
> On Thu, 18 Nov 2004 09:48:47 -0000, "Simon Harvey"
> <sh856531@.microsofts_free_email_service.com> wrote:
>
Simon Harvey wrote:[vbcol=seagreen]
> Hi all
> Should implement a transaction in both the stored procedure AND in
> ADO.net code or is doing it in one or the other good enough to
> protect against concurrency and atomicity problems?
> Thanks
> Simon
> "Mary Chipman" <mchip@.online.microsoft.com> wrote in message
> news:8egpp052lm2jkkuv2e5dik0k1h4pvgncc4@.4ax.com...
If you're talking about SQL running from a client as opposed to running
a single stored procedure, I think you have to go the SP route (in most
cases). Security aside, imagine running 20 SQL commands from a client on
the server in succession: each one requires a full round-trip to the
server which can slow things down. OTOH, a single SP is a single call.
While the slower client-side transaction runs, it holds locks on the
server, which in turn causes other transactions to wait on locked
resources which slows everyone down.
Plus, if you have to make an implementation change, you don't have to
deal with recompiling the app and distributing it to everyone.
David Gugick
Imceda Software
www.imceda.com
|||A transaction has to be ATOMIC regardless of who starts it otherwise what
good is it. So two transactions are not better than one in this case. If
the outer one is Rolled back then ALL the nested ones are too. Sometimes it
makes sense to have trans in sp's so that if you call the sp by itself
everything inside it is all or nothing. But if you begin a tran from
outside a sp, everything from there on will be wrapped in that same tran.
Andrew J. Kelly SQL MVP
"Simon Harvey" <sh856531@.microsofts_free_email_service.com> wrote in message
news:eOl8GlkzEHA.1204@.TK2MSFTNGP10.phx.gbl...
> Hi all
> Should implement a transaction in both the stored procedure AND in ADO.net
> code or is doing it in one or the other good enough to protect against
> concurrency and atomicity problems?
> Thanks
> Simon
> "Mary Chipman" <mchip@.online.microsoft.com> wrote in message
> news:8egpp052lm2jkkuv2e5dik0k1h4pvgncc4@.4ax.com...
>
|||Except that sometimes you need to do something and then do more things in
source code that depend on that something and so on. Unless you move your
entire application into the SP, you'll have no choice but to wrap the
transaction into an ADO.NET call. Apart from the fact that (in our case) it
may not be feasible to rewrite 2.5 million lines of code to accomodate SP
only transactions, not to mention that some of the older parts of the code
(that are being rewritten into .NET) use embedded SQL...
You'll just have to evaluate your application architecture if it already
exists, or decide how you will be accessing the data at all times in your
application of you are currently designing it. There's a time and place for
everything. But know this, if you begin a transaction in the SP and for
some reason need to execute source code that may depending on something from
a currently running transaction, and it attempts to start a transaction and
call an SP that starts its own transaction, you'll get an exception. So you
either do it one way or another but not both, unless you want to excercise
your patients and stamina.
Thanks,
Shawn
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:ut0iiRlzEHA.824@.TK2MSFTNGP11.phx.gbl...
> Simon Harvey wrote:
> If you're talking about SQL running from a client as opposed to running
> a single stored procedure, I think you have to go the SP route (in most
> cases). Security aside, imagine running 20 SQL commands from a client on
> the server in succession: each one requires a full round-trip to the
> server which can slow things down. OTOH, a single SP is a single call.
> While the slower client-side transaction runs, it holds locks on the
> server, which in turn causes other transactions to wait on locked
> resources which slows everyone down.
> Plus, if you have to make an implementation change, you don't have to
> deal with recompiling the app and distributing it to everyone.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>
|||Shawn B. wrote:
> Except that sometimes you need to do something and then do more
> things in source code that depend on that something and so on.
> Unless you move your entire application into the SP, you'll have no
> choice but to wrap the transaction into an ADO.NET call. Apart from
> the fact that (in our case) it may not be feasible to rewrite 2.5
> million lines of code to accomodate SP only transactions, not to
> mention that some of the older parts of the code (that are being
> rewritten into .NET) use embedded SQL...
> You'll just have to evaluate your application architecture if it
> already exists, or decide how you will be accessing the data at all
> times in your application of you are currently designing it. There's
> a time and place for everything. But know this, if you begin a
> transaction in the SP and for some reason need to execute source code
> that may depending on something from a currently running transaction,
> and it attempts to start a transaction and call an SP that starts its
> own transaction, you'll get an exception. So you either do it one
> way or another but not both, unless you want to excercise your
> patients and stamina.
>
> Thanks,
> Shawn
I thought the OP asked a simple question: Which is better to use in an
application SPs or embedeed SQL. The answer to _that_ simple question is
stored procedures. But that's not the question he asked. He asked
whether the transaction should be started in the app or on in the SP. I
think Andrew answered that question. But I stand by answer to a question
that was never asked :-)
David Gugick
Imceda Software
www.imceda.com
|||I think the relevance, while not as direct as previous answers, is that "it
depends on how your code and workflow is organized". I'm not dissagreeing
with the "simple" answer, that you use transactions in the SP. However,
I've rarely encountered a business application that was designed in such a
way that all transactions were at the SP level. I was only offering a
difference perspective, a difference way of looking at things, another thing
to take into consideration. Nothing more.
Thanks,
Shawn
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:u4zdwPmzEHA.3336@.TK2MSFTNGP11.phx.gbl...
> Shawn B. wrote:
>
> I thought the OP asked a simple question: Which is better to use in an
> application SPs or embedeed SQL. The answer to _that_ simple question is
> stored procedures. But that's not the question he asked. He asked
> whether the transaction should be started in the app or on in the SP. I
> think Andrew answered that question. But I stand by answer to a question
> that was never asked :-)
>
> --
> David Gugick
> Imceda Software
> www.imceda.com
>
|||Shawn B. wrote:
> I think the relevance, while not as direct as previous answers, is
> that "it depends on how your code and workflow is organized". I'm
> not dissagreeing with the "simple" answer, that you use transactions
> in the SP. However, I've rarely encountered a business application
> that was designed in such a way that all transactions were at the SP
> level. I was only offering a difference perspective, a difference
> way of looking at things, another thing to take into consideration.
> Nothing more.
>
> Thanks,
> Shawn
>
I agree with you Shawn. Unless you have strict standards (which are not
bad to have), most applications will have some embedded SQL, even if
using SPs is the standard. Although, I'm not sure if you have an SP
standard for an app that ending up with a mixed code base is good from a
maintenance and security standpoint. It's nice to know no one can access
your database, except through stored procs.
David Gugick
Imceda Software
www.imceda.com
|||Hi all,
Thanks for your answers so far.
I'm still not sure about something. Are ADO.net transactions and TSQL
transactions essentially equivelent?
If I do a big stored procedure, locked through ADO.net, will all the the
rows be locked until the SP returns?
I'm worried that if I use ADO, the stored procedure still might cause a
concurrency problem. This is essentially my problem.
Thanks again
Simon
|||Simon,
An ADO transaction (.net or otherwise) is nothing more than passing a BEGIN
TRAN to SQL Server. So it's always a SQL Server transaction and any rows
locked after the first Begin Tran is issued (regardless of where or by who)
on that connection will remain locked until the final commit (if nested) or
the first Rollback.
Andrew J. Kelly SQL MVP
"Simon" <sh856531@.microsofts_free_email_service.com> wrote in message
news:%23GAkzXyzEHA.3336@.TK2MSFTNGP11.phx.gbl...
> Hi all,
> Thanks for your answers so far.
> I'm still not sure about something. Are ADO.net transactions and TSQL
> transactions essentially equivelent?
> If I do a big stored procedure, locked through ADO.net, will all the the
> rows be locked until the SP returns?
> I'm worried that if I use ADO, the stored procedure still might cause a
> concurrency problem. This is essentially my problem.
> Thanks again
> Simon
>
|||Andrew J. Kelly wrote:
> Simon,
> An ADO transaction (.net or otherwise) is nothing more than passing a
> BEGIN TRAN to SQL Server. So it's always a SQL Server transaction
> and any rows locked after the first Begin Tran is issued (regardless
> of where or by who) on that connection will remain locked until the
> final commit (if nested) or the first Rollback.
>
I would add that if concurrency is a concern, letting SQL Server start
and end the transaction from within the SP will be faster than doing so
from .net because it will eliminate 2 additional round-trips to the
server.
David Gugick
Imceda Software
www.imceda.com