DataSource Controls :: "Connection Property Has Not Been Initialized"
Apr 30, 2010
I am trying to setup my page with a drop down which value comes from one SQL query and item list comes from another SQL query to the same database...
what I want to do is:
read 1 line from bugs table. this line includes a projectid which will be the value of the drop down. I also read the projects table for active projects/id and load this as drop down items....
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
conn.Open();
using (SqlCommand bug = new SqlCommand(
"SELECT bugs.id, bugs.projectid, bugs.typeid, bugs.subtypeid, bugs.version, bugs.summary, " +
"users.email AS creator, bugs.createddate, bugs.text, bugs.closeddate, bugs.history " +
"FROM bugs INNER JOIN users ON bugs.creatorid = users.id WHERE (bugs.id = @idd)", conn))
{
bug.Parameters.AddWithValue("idd", Request.QueryString["ID"]);
try
{
SqlDataReader reader = bug.ExecuteReader();
if (reader.Read())
{
String projectid = reader[1].ToString();
// read project name list...
using(conn) using (SqlCommand projects = new SqlCommand("SELECT name, id FROM projects WHERE active=true"))
try
{
SqlDataReader pr = projects.ExecuteReader(); // This line causes the exception... what am I doing wrong?
while (pr.Read()) project.Items.Add(new ListItem(reader[0].ToString(), reader[1].ToString()));
}
catch { }
In some posts I have read on other forums, those with database connection problems (I am thinking about Access) sometimes get the error: 'Connection property has not been initialized' which might translate as 'you have not kick-started your connection'. One reason for that, according to a number of replies I have come across, is that 'you have not set the connection property of the command object' ('you have not told command how to connect').
So would something like this:
Code: Dim conn As New OleDbConnection Dim OleDbConnection As New OleDbConnection Dim cmd As New OleDbCommand conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|myDatabase.mdb;" conn.Open() cmd = New OleDbCommand("SELECT strName FROM school WHERE strName=@strName", conn) cmd.Parameters.AddWithValue("@strName", UserName.Text) cmd.Connection = conn cmd.ExecuteNonQuery() conn.Close()
a) initialise the connection property and b) set the connection property of the command object?
I am getting error ExecuteReader: Connection property has not been initialized. below is the code i am using.
SqlDataReader oReader = new SqlDataReader(); string sSQL = @" WITH TAB_CTE AS ( SELECT fbominum, fbompart, fparinum, flevel, fsono FROM sodbom WHERE fbompart= @fbompart and fsono = @fsono UNION ALL SELECT e.fbominum, e.fbompart, e.fparinum, e.flevel, e.fsono FROM sodbom e INNER JOIN TAB_CTE ecte ON ecte.fbominum = e.fparinum where e.fsono = @fsono ) SELECT * FROM TAB_CTE where fbompart <> @fbompart "; SqlCommand oCommand = new SqlCommand(sSQL, this._connection); oCommand.CommandType = System.Data.CommandType.Text; oCommand.Parameters.Add("@fbompart", ItemSODBOM.fbompart); oCommand.Parameters.Add("@fsono", ItemSODBOM.SONO); oReader = oCommand.ExecuteReader();//Here I am getting error
I am getting above mentioned error when I try to run the following code:
Private strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString Private con As New SqlConnection(strConnString) Private pID As Integer 'FIRST SECTION Dim query As String = "query" Dim cmd As New SqlCommand(query)
[Code] .....
The error is coming from the second SQL cmd but if I comment out the first section; the second section runs fine.
I must have made another basic error but I just can't figure out what it is.
I have one intranet based application.I have set windows authentication for it in Web.config as well as from IIS settings. While running my application through the source code, it works fine but while running from directly IIS then its giving me:
public class DataClass{   public DataClass()   {   }   /// <summary>   /// return rows depend on position   /// if you need 10th to 20th you need to pass start=10 and end=20   /// </summary>   /// <param name="start">database start position of one row</param>   /// <param name="next">database end position of one row</param>   /// <returns></returns>   public string GetAjaxContent(int start, int end)   {         Â
[code].....
When I'm trying to develop the unlimited scrolling in datalist i have an error like connection string not initialized I checked and rechecked.
Im using two stored procedures to write and update values in a SQL DB. Im using the SQLDatasource update method. When I run the webpage on my development server everything runs fine. When I try and run the web page on my Live server I get the following error :System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding This always takes 30 seconds to fail - and looking at google it seems that this is a connection timeout error.In my web.config file I have updated the connectionstring line to include a timeout setting :
When I open an ASP.NET 3.5 project using VWD2010, I get a prompt error message,"The connection property in the web.config file is missing or incorrect.The connection string from the .dbml file has been used in its place."however, my project works successfully.
I have been looking through the event viewer on our server and can see quite a few people with this error but I can't replicate this myself but it is causing issues for people viewing our website is there anyway I can "initialize" Command Text property?
UPDATE
So I have this query
datelistquery = "SELECT DISTINCT property_id, ' - Sleeps ' + cast(number_slept as varchar) as combsleeps, number_slept FROM openquery ("+Application("hpbDsrc")+",'SELECT property_id, number_slept FROM web_details WHERE part_full_flag = ''F'' AND location = ''"&Session("TenChosenLocCode")&"'' AND property_id = ''"&Session("passedPropId")&"'' AND pets_yn like ''"&Session("TenPets")&"'' AND number_slept >= ''"&Session("TenAdults")&"'' AND year_week = ''"&Session("TenHolStDateHP1")&"'' AND on_hold = ''NO'' AND booked = ''NO'' ') ORDER BY number_slept, property_id"
So should I put at the start sqlCommand.CommandText(datelistquery) = "Select Distinct...."
I need to configure a property of a custom control I wrote, specifically before the control calls OnInit. If I assign it as part of the ASPX file, it naturally works, but if I instead move the assignment to different parts of the code-behind, it will throw an error for having an empty and invalid value. The following is what it looks like when functional in the ASPX page.
The property in question is FilterString, which is just a simple string. It should be noted as well that the FieldName property (inheritted from the control's base class "BaseFieldControl") would also throw an error if it is not initialized, but if I set FieldName in the code behind's OnInit method, it works correctly. FilterString is not so, it won't actually be assigned. So I know that some methods for certain properties will work for setting the property's value, but it won't always work. I tried placing it in OnPreInit as well, to no avail.
I am taking a dynamic assignment approach because the functionality of this page needs to be replicated for a number of different lists, and the FilterString and FieldName properties will differ in every case. Rather than write half a dozen mostly-identical aspx pages all with the same code behind but differing just in what those two properties are, I figured it would be wiser to use the page's query string and some derived parameters to set those properties dynamically. As such, what methods are available to accomplish this task?
In my DAL i have more than 100 methods/Function, each and every method am opening the sqlconnection and closing the connection, this is taking too much of time to establish the connection at every time. So what i expect is one common class will create the SqlConnection that will check if the connection is Broken or Closed then create the connection again else return the connection, how to do this(Also i would like to apply ConnectionPooling).
As you can see, the connectionstring parameter is defined to a specific connection string name and I need to be able to set such a parameter to a different value, for example, to a session variable content.
i am trying to create connection using OLEDB connection in my app. but i am not able to create the connection as in datasource i want to use Server.mappath, but cudn't find the right method to use it. i am trying to make connection with Access database file. following is code i have tried:
string path = Server.MapPath("~/uploadaccess/Production.mdb"); string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("~/uploadaccess/Production.mdb")&";"; and also OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path&";"); and tried this OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("~/uploadaccess/Production.mdb"));
and this is the error i am getting:
Operator '&' cannot be applied to operands of type 'string' and 'string'
Traditionally with an Object Data Source, the wired up class will have its public properties available for binding (i.e. Gridview columns, etc.) which works well. But what if one of my wired up business objects has a property that is an object itself; can I drill down to a property on that object property and still use it?
So in additiona to the traditional:MyBusniessObject.OrderID...I want to use:MyBusniessObject.Customer.NameID Your 1st response might be to just wire up the 'Customer' class, but I need properties both on 'MyBusinessObject'and 'Customer'. I do not think this can be done, as the ODS will not display properties on an object instance property. I have tried manually typing in the drilled down value as well, but that wasn't a success either.
I am storing a custom "Organisation" object as a session variable. One of the properties of the Organisation object is "OrganisationID" (integer). I have a DataSource that requires a parameter value to run, and I want to use a SessionParameter to populate this. In a previous version, I stored the OrganisationID directly as a session variable. In that case, I could easily access it like this:
[Code]....
However, how do I now access the OrganisationID property of an "Organisation" type session variable (called "Organisation")? I have tried this, which does not seem to work: <asp:SessionParameter Name="OrganisationID" SessionField="Organisation.OrganisationID" Type="Int32" />
i have an asp page through which i want to access FTP server And retrieve data (only file properties )from there and get it in excel (or just display it on the browser)is there any way i can keep it simple and acess the data from the server ???
Am I right in assuming that only after controls on Master page are merged into the control tree for the Page, can controls ( both those in Master page and in a content Page ) be initialized with their declarative values ( values set during design time)? b) If my above assumption is correct, then these controls cannot be initialized with their design-time values during Page.PreInit, since during Page.PreInit event stage we're still able to dynamically set a Master page?! So if that is the case, when are controls initialized with their declarative values? During Init event orâ€
The attached code, the oledb part, is giving me a blank web page saying it cant connect on my local dev server. I have another app with the same code, in fact I copied it and changed the db names. The one I copied from works fine.