473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Exceute scalar need s an open and availble connection

hi to all ,
i am new to .Net development.
i have developed a service which doing some operation along with database. i have developed an another application which will insert the data into the database and tells the service to get the inserted data.this application works fine when at a time only one request is sent. but it fails when more than 5 . from service i will connect to database whenever i need and then i will close. the service throws an error "Executescalar requires an open and available connection".how to solve this issue?

thanks in advance
Sep 2 '08 #1
4 1333
kenobewan
4,871 Expert 4TB
What database are you using? Please show us your relevant code. Thanks.
Sep 2 '08 #2
i am using Sql server 2000:
my database file code is
Expand|Select|Wrap|Line Numbers
  1. class DataBase
  2.     {
  3.         OleDbConnection Con;
  4.         OleDbCommand Cmd;
  5.         private void CloseConnection()
  6.         {
  7.             try
  8.             {
  9.                 Cmd.Dispose();
  10.                 Con.Close();
  11.             }
  12.             catch (Exception excp)
  13.             {
  14.                 ErrorLog.WriteError("CloseConnection", excp.Message);
  15.             }
  16.         }
  17.  
  18.         public String GetResult(String Qry)
  19.         {
  20.             String Result = "" ;
  21.             try
  22.             {
  23.                 EstablishConnection();
  24.                 Cmd.CommandText = Qry;                
  25.                 if (Cmd.ExecuteScalar() == null)
  26.                 {
  27.                     Result = "Empty";
  28.                 }
  29.                 else
  30.                 {
  31.                     Result = Cmd.ExecuteScalar().ToString();
  32.                     if (Result == "")
  33.                         Result = "Empty";
  34.                 }
  35.                 CloseConnection();
  36.             }
  37.             catch (Exception excp)
  38.             { 
  39.                 ErrorLog.WriteError("Get Result:", excp.Message);
  40.             }
  41.                 return Result;
  42.            }
  43.  
  44.         private void EstablishConnection()
  45.         {
  46.             Con = new OleDbConnection();
  47.             Cmd = new OleDbCommand();
  48.             try
  49.             {
  50.                 Con.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"].ToString();
  51.                 Cmd.Connection = Con;
  52.                 Con.Open();
  53.             }
  54.             catch (Exception Excp)
  55.             {
  56.                 PopupCls.ShowMessage("Error in Database Connection *DataBase");
  57.                 ErrorLog.WriteError("Connection Establishment", Excp.Message);
  58.             }
  59.  
  60.         }
Another application will call the service and the service executes the above code


i gets error in the bolded text function execution when the client application calls the service repeatedly;


Thanks in advance
Sep 2 '08 #3
kenobewan
4,871 Expert 4TB
Not sure why if (Cmd.ExecuteScalar() == null) else block is necessary or which error is bolded. Try returning boolean values and debugging.
Sep 3 '08 #4
Not sure why if (Cmd.ExecuteScalar() == null) else block is necessary or which error is bolded. Try returning boolean values and debugging.

thanks for Your reply.Actually i did mistake in objecxt initialization.any way thanks for your replies
Sep 6 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: frankie | last post by:
I have a problem When I execute scalar to retreive some data,if it is not found I get an error which I cannot trap When nothing is found, response is "" (length=0), but it comes from catch. Also,...
5
by: Bob Stearns | last post by:
When I run the following query with the two sections commented out, the response time is between 1 an 2 seconds; with the first indicated section enabled, the response goes up to 15 seconds even...
0
by: frankie | last post by:
I have a problem When I execute scalar to retreive some data,if it is not found I get an error which I cannot trap When nothing is found, response is "" (length=0), but it comes from catch. Also,...
7
by: Alan Pretre | last post by:
I have an application installed at a customer site that has been getting a general network error for a couple of years. I was hoping that .NET 2.0 would clear it up, but unfortunately it didn't. ...
2
by: Oded Dror | last post by:
Hi there, Please take a look at the source code and tell me whats wrong? Imports System.Data Imports System.Data.SqlClient Partial Class Test Inherits System.Web.UI.Page Const conString As...
0
by: Saurov | last post by:
To execute/open a file(say a.XML) in IE I use System.Diagonistic.Process.Open("explorer.exe",file). But the user can use any browser like opera, konquerror, mozilla, netscape etc. So I wanna to...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
2
by: alnoir | last post by:
I've looked around online and have even had a friend help me, however, for some reason I can't compare two strings. I'm doing this at the end of the code (within the two foreach loops), above...
1
by: Tony M | last post by:
vs 2005 - vb .net - web forms - xp pro Can't figure out why I keep getting the error Must declare the scalar variable "@CheckUser". The error happens on SqlDA.Fill(SqlDS). Just trying to make...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.