Peter,
Here is the process we are using. Someone brainless where I work wrote a
wrapper object looking just like the Microsoft command object and even named
it the same/simular. I'm not opening a connection, I'm setting the
connection string to the command object and even disposing it and setting it
to null in the finally statment. Well here it is... hope it's not too long.
public virtual void Search(string p_firstName, string p_lastName, string
p_email,
string p_city, string p_state, string p_zip, string p_issue, string
p_companyName, int p_siteId,
int p_statusId)
{
SqlClient command = null;
try
{
command = new SqlClient(conne ctionString);
command.SetInpu tParameter("@p_ FirstName", SqlDbType.VarCh ar,
p_firstName);
command.SetInpu tParameter("@p_ LastName", SqlDbType.VarCh ar, p_lastName);
command.SetInpu tParameter("@p_ Email", SqlDbType.VarCh ar, p_email);
command.SetInpu tParameter("@p_ City", SqlDbType.VarCh ar, p_city);
command.SetInpu tParameter("@p_ State", SqlDbType.VarCh ar, p_state);
command.SetInpu tParameter("@p_ Zip", SqlDbType.VarCh ar, p_zip);
command.SetInpu tParameter("@p_ Issue", SqlDbType.VarCh ar, p_issue);
command.SetInpu tParameter("@p_ CompanyName", SqlDbType.VarCh ar,
p_companyName);
//command.SetInpu tParameter("@p_ TaskDateTime", SqlDbType.DateT ime,
p_taskDateTime) ;
//command.SetInpu tParameter("@p_ TaskActivityCom ment", SqlDbType.VarCh ar,
p_taskActivityC omment);
//command.SetInpu tParameter("@p_ TaskActivityLas tModDate",
SqlDbType.DateT ime, p_taskActivityL astModDate);
command.SetInpu tParameter("@p_ SiteId", SqlDbType.Int, p_siteId);
command.SetInpu tParameter("@p_ StatusId", SqlDbType.Int, p_statusId);
Load(command, "Search");
}
catch(Exception ex)
{
throw ex;
}
finally
{
command.Dispose ();
command = null;
}
}
protected virtual void Load(SqlClient command, string commandText)
{
IDataReader reader = null;
Search search = null;
try
{
//Execute command object
command.Execute SqlCommand(comm andText, out reader);
//Iterate through reader object to read and set the values
while(reader.Re ad())
{
search = new Search(base.con nectionString);
//Set the reader field values to channel object
search.SetValue s(reader);
//Add to chanels collection
this.Add(search );
search = null;
}
}
catch(Exception ex)
{
throw ex;
}
finally
{
reader.Close();
reader.Dispose( );
reader = null;
search = null;
command.Dispose ();
command = null;
}
}
private void executeSqlComma nd(string CommandText, out
IDataReader DataReader)
{
this.Command = new sqlClient.SqlCo mmand(CommandTe xt);
this.Command.Co mmandTimeout = 15;
this.ExecuteSql Command(this.Co mmand, CommandType.Sto redProcedure, out
DataReader);
}
public virtual void SetValues(IData Reader reader)
{
try
{
if (reader["ContactId"] != DBNull.Value)
contactId = Convert.ToInt32 (reader["ContactId"]);
if (reader["TaskId"] != DBNull.Value)
taskId = Convert.ToInt32 (reader["TaskId"]);
if (reader["LastName"] != DBNull.Value)
lastName = reader["LastName"].ToString();
if (reader["FirstName"] != DBNull.Value)
firstName = reader["FirstName"].ToString();
if (reader["City"] != DBNull.Value)
city = reader["City"].ToString();
if (reader["State"] != DBNull.Value)
state = reader["State"].ToString();
if (reader["Zip"] != DBNull.Value)
zip = reader["Zip"].ToString();
if (reader["Email"] != DBNull.Value)
email = reader["Email"].ToString();
if (reader["Issue"] != DBNull.Value)
issue = reader["Issue"].ToString();
if (reader["CompanyNam e"] != DBNull.Value)
companyname = reader["CompanyNam e"].ToString();
// if (reader["TaskActivityCo mment"] != DBNull.Value)
// taskActivityCom ment = reader["TaskActivityCo mment"].ToString();
if (reader["SiteId"] != DBNull.Value)
siteId = Convert.ToInt32 (reader["SiteId"]);
if (reader["StatusId"] != DBNull.Value)
statusId = Convert.ToInt32 (reader["StatusId"]);
// if (reader["ActivityNa me"] != DBNull.Value)
// activityname = reader["activityna me"].ToString();
}
catch(Exception ex)
{
throw ex;
}
}
"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com wrote in message
news:B1******** *************** ***********@mic rosoft.com...
Doug,
You haven't included any of the code from your searchs object so nobody
can
really tell what you are doing code-wise there. However, if it works the
first time and you get a connection failure in subsequent attempts you can
be
pretty sure it's because the original (first) connection wasn't closed /
disposed properly.
Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"Doug Durrett" wrote:
>I'm having an issue and wanted to pass it by everyone to see what you
think.
Here is my code.
//Code Start
searchs = new
Maritz.Learnin g.HP.Callcenter .BusinessServic es.Searchs(base .ConnectionStri ng);
searchs.Search (this.FirstName Textbox.Text, this.LastNameTe xtbox.Text,
this.EmailText box.Text, this.CityTextBo x.Text, this.StateTextB ox.Text,
this.ZipTextBo x.Text, this.IssueTextB ox.Text,
this.CompanyNa meTextBox.Text,
Convert.ToInt3 2(this.SiteDrop DownList.Select edValue.ToStrin g()),
Convert.ToInt3 2(this.StatusDr opDownList.Sele ctedValue.ToStr ing()));
this.ResultsDa taGrid.DataSour ce = searchs;
this.ResultsDa taGrid.DataBind ();
//Code End
This is on a click event from a web page. When the button is clicked
the
searchs object is created and populated from a sproc. Then simply set
the
datasource and bind it. This works perfectly, however, if I click the
button a 2nd, 3rd, or 4th time (usually on the 4th click) everything
works
until I get to the DataBind(). The system will hang on that line and
produce this error.
Server Error in '/' Application.
--------------------------------------------------------------------------------
Failed to open a data connection
Server=FENSQLL IBD01;database= HPCustomerSuppo rt;user
id=HPCustomerS upport;password =*2rT44Y* - please check the connection
string
and security settings!
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Exceptio n: Failed to open a data connection
Server=FENSQLL IBD01;database= HPCustomerSuppo rt;user
id=HPCustomerS upport;password =*2rT44Y* - please check the connection
string
and security settings!
Source Error:
An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[Exception: Failed to open a data connection
Server=FENSQLL IBD01;database= HPCustomerSuppo rt;user
id=HPCustomerS upport;password =*2rT44Y* - please check the connection
string
and security settings!]
Maritz.Learnin g.HP.Web.CallCe nter.Tracking.s earchtask.Searc hButton_Click(O bject
sender, EventArgs e) in c:\inetpub\wwwr oot\hplogging\s earch.aspx.cs:9 0
System.Web.UI. WebControls.But ton.OnClick(Eve ntArgs e) +108
System.Web.UI. WebControls.But ton.System.Web. UI.IPostBackEve ntHandler.Raise PostBackEvent(S tring
eventArgumen t) +57
System.Web.UI. Page.RaisePostB ackEvent(IPostB ackEventHandler
sourceContro l,
String eventArgument) +18
System.Web.UI. Page.RaisePostB ackEvent(NameVa lueCollection postData) +33
System.Web.UI. Page.ProcessReq uestMain() +1277
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.432 2.573;
ASP.NET
Version:1.1.43 22.573
Has anyone ever seen anything like this?
Doug