.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Web config connection string error: a field initializer can not reference the nonstatic field

Posted By:      Posted Date: September 27, 2010    Points: 0   Category :ASP.Net


I am try to get connection string from web config, but I got error" a field initializer can not reference the nonstatic field, method, or property '_default.connStr'. I search a lot. It says that I need constructor, but I am not sure how to write the constructor at class: public partial class _Default : System.Web.UI.Page

Here is my code:

{public partial class _Default : System.Web.UI.Page

    string txt;
    string username;
    OleDbCommand myCommand = null;
    OleDbDataReader myDataReader = null;

//retrieve the connection string from the ConnectionString Key in Web.Config
    string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    //create a new OleDB connection
    OleDbConnection myConnection = new OleDbConnection(connStr);

protected void Page_Load(object sender, EventArgs e)

            string strOledb = @"select * from tableone";
            OleDbCommand myCommand = new OleDbCommand(strOledb);

View Complete Post

More Related Resource Links

Simple error connection string null reference

 It is failing on SqlHelper.ExecuteNonQuery(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString     public static string GetAboutMeName(string sUserID, string connectionString)        {             SqlParameter[] parameters = new SqlParameter[2];                      parameters[0] = new SqlParameter("@sUserID", SqlDbType.VarChar, 50);            parameters[0].Value = sUserID;             parameters[1] = new SqlParameter("@sResult", SqlDbType.NVarChar, 1000);            parameters[1].Direction = ParameterDirection.Output;             // Execute the stored procedure            SqlHelper.ExecuteNonQuery(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString, CommandType.StoredProcedure, "sprGetAboutMeName", parameters);         &n

An object reference is required for the nonstatic field, method, or property 'object.GetType()'


I'm getting this error, what i'm missing?

error: An object reference is required for the nonstatic field, method, or property 'object.GetType()'


static public void RegisterScriptMethod(System.Web.UI.Page page, string methodName, string methodBody)


StringBuilder sb = new StringBuilder();


"<script language='javascript'>");


"function " + methodName + " {" + methodBody + "}");



//page.RegisterClientScriptBlock(methodName, sb.ToString());

Modifying connection String in Web config using Install Wizard



Im trying to create a Web Deployment Project, the built in setup and deployment is very good in Visual Studio, i need to able to add an additional step in the setup to change the connection string in the Web config file. Ive seen a lot of articles on how to do this and in particular this http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx#7162670 I am however stuck on the final part of this tutorial, im using the code Scott provided but have two errors,  heres part of my code where the errors are

using System;
using System.Configuration;
using System.Configuration.Install;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.DirectoryServices;

 void ConfigureDatabase(string targetSite, string targetVDir, string connectionString)
            // Retrieve "Friendly Site Name" from IIS for TargetSite
            DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSit

How to read a column of a sharepoint list to a text string field of infopath form?

My infopath form used to read these email addresses from a web service and web.config file. Now i would like to get these user email addresses from a contact list in a sharepoint server. I am trying to do this without writing any codes. Here is what i have done so far: 1. Adding a new "data connection to receive data from SharePoint library or List" where i selected Email Address column of the contact list. 2. I added a new Text Field and define a new rule with "Query using a data connection" defined above. When i try to access the newly created Text field above it always return empty as if the Query attached to it did not executed at all. What did i do wrong? Is there a better way? Thank you in advance for your help.

Writing connection string in web.config file by code or dynamically

I want to write connection string in web.config file of my application by code. If anyone know the way or code just help me..NET,C#,SQL SERVER

Problem when deployind ContentType: Error occurred in deployment step 'Activate Features': Field t

Im getting this error when i try to Deploy my ContenType: Error occurred in deployment step 'Activate Features': Field type GUID is not installed properly. Go to the list settings page to delete this field Does someone know how to fix this error? The ContentType is defined as: <     Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <!--Site columns--> <Field Name="Test" DisplayName="Customer Subject ID" ID="{38A9E5BA-62FF-4F3B-90E3-F9961FEABE20}" Type="Text" Required="FALSE" /> <!--Parent ContentType: Item (0x01) --> <ContentType ID="0x01004317ec735b25468583d7470aa17c36ae" Name="NextContentTypes - NextCustomerContentType" Group="Next Content     Types"Description="NextCustomerContentType" Inherits="TRUE" Version="0"> <FieldRefs> <!-- References to field difinitions --> <FieldRef ID="{38A9E5BA-62FF-4F3B-90E3-F9961FEABE20}" Name="Test"></FieldRef> </FieldRefs> </ContentType> </     Elements>

infopath 2007 Expected value type: end-of-string ! calculated field

Hello I am using infopath since there is no field with type date and time in InfoPath 2007. I created three fields one for date one, for hours, and one for minutes then I created forth field that concatenate the values of the three fields this field will be used as column in form template library used by my form. All seems good so far but when I tried to concatenate those fields go the following error Expected value type: end-of-string how can I solve this ? my xpath looks like ../my:calmomoDate../my:cbmomoHours:../my:cbmomoMunites Thanks  Momo

Flat file upload: Error when inserting into datetime field.

Hi All I am having an issue with uploading a txt file into an SQL table and one of the fields needs to go into a datetime column. The issue is with column3 I have been into the advanced editor of the flat file source and set the output column to decimal and it fails. The error I am getting is below: Error: 0xC02020A1 at Materials Transfer, Flat File Source [1]: Data conversion failed. The data conversion for column "Column 3" returned status value 2 and status text "The value could not be converted because of a potential loss of data.". Error: 0xC0209029 at Materials Transfer, Flat File Source [1]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "output column "Column 3" (48)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "Column 3" (48)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure. Error: 0xC0202092 at Materials Transfer, Flat File Source [1]: An error occurred while processing file "D:\Development\r3_downloads\mat.txt" on data row 1. Any help would be great.   Thanks BigGopher

Sum of Calulated field in a group error when containing a value $0

Hi, I have a group which sums the total of the calculated field with expression: =SUM(Fields!MTD_VAR_CY_v_LY_D.Value) If one of the value in the child row for Fields!MTD_VAR_CY_v_LY_D.Value is 0, the group will display #Error. Anyone knows why this is the case?

A customized EditForm.aspx page giving error because it has a "People and Group" field with a "Allow

My customized EditForm.aspx which has a "People and Group" column with the "Allow multiple selections" property as "Yes" was working fine until the Agusust cumulative update was applied into the MOSS server. Now it's giving me the error: "An unexpected error has occurred". Needless to say, when I change the "Allow multiple selections" property to "No", the customized EditForm.aspx page works fine.Forgetting whyMicrosoft introduced this error for now, is there a workaround that you are awre of?

"String or binary data would be truncated" and field specifications

Hi all,   i have "String or binary data would be truncated" error when i try to execute an insert statment.   can i find witch field is affected by this error? (for return it to the user)   thank's all

How to set a string field with people picker control group

Hi Guys I have a problem with a form list, when I need to set a string field with de content of people picker control that have more than one "user". Is there any way to put in string a list of user like the people picker control shows in a form? The really problem is I don't know how to read an array of user in a formula rule. any example or idea should be appreciated. tnks.  

Error occurred in deployment step 'Activate Features': Invalid field name.

Hi, I've a empty sharepoint project where i've added a content type that looks like this: <?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Field ID="{45067EC7-078C-46A1-A075-E422C000215E}" Name="Schedule" DisplayName="Schedule" Group="Custom Fields" Type="Choice" Required="TRUE"> <CHOICES> <CHOICE>Minute</CHOICE> <CHOICE>Hour</CHOICE> <CHOICE>Day</CHOICE> </CHOICES> <Default>Hour</Default> </Field> <Field ID="{938CAAA4-C1AD-4E39-93D8-9C463391E006}" Name="Interval" DisplayName="Interval" Group="Custom Fields" Type="Integer" Required="TRUE" /> <Field ID="{3AD33CEA-6382-4BEE-8BB2-1C0902F13472}" Name="LastRun" DisplayName="Last Run" Group="Custom Fields" Type="Text" MaxLength="255" Required="FALSE" ReadOnly="TRUE" ShowInDisplayForm="TRUE" /> <!-- Parent ContentType: Document (0x0101) --> <ContentType ID="0x010100c293443c01ed4ac893ea199180df0244" Name="My Content Type" Group="Custom Content Types" Description=&quo

Duplicate field name error, creating new site from custom template

I've made a site that maps the site (with a table of contents) and i export it to another site collection. I'm able to install and activate the solution in the other site collection, however when i'm going to create a new site using the site i've installed as a template it pops an error saying "A duplicate field name Wiki_x0020_Page_x0020_CategoriesTaxHTField" was found." I have no clue what this means. Can anyone help me? Thanks in advance

InfoPath / ActiveX error when using person selector field in Word template off SharePoint document l

I have created an out-of-the-box document library on a SharePoint 2010 site.  I left Microsoft Word Document selected as the Document Template.  I then added a person or group column and a multiple lines of text column to the document library. I then went into Library Settings --> Advanced Settings and clicked on Edit Template, opening the template in Word.  I created my template and added the two new columns to the document.  I did this using the Quick Parts --> Document Property --> [column name] feature under the Insert tab in Word.  I then saved the template back to SharePoint. Upon opening the template or creating a new document from the template, I get the following dialog box: --------------------------- Microsoft Office InfoPath --------------------------- One or more ActiveX controls could not be displayed because either: 1) Your current security settings prohibit running ActiveX controls on this page, or 2) You have blocked a publisher of one of the controls. As a result, the page might not display correctly. --------------------------- OK   --------------------------- I've searched around (I believe fairly extensively) and have not run into anyone else with the same issue.  Some have mentioned a similar error when creating a custom document information panel in InfoPath, and suggested lowered ActiveX security setti

Encrypting config file's connection string and keys


 Is aspnet_regiis.exe secure? If i encrypt using aspnet_regiis.exe, will it automatically decrypt the string and wont give any error? Need an insight into this stuff....any suggestions? Is Rsa the best option or wat? Wat's the best way to encrypt/decrypt programmatically?

Calculated field error



 tried to add a Calculated filed for cumulative total

with the following expression =runningvalue(fields!ReceiptQty.Value,sum,nothing)

it is giving error like

"An error accurred during local report processing.  The definition of report is not valid.

An internal error occured on the report server. See the error log for more details"

 Pls somebody help what is or where am I wrong????

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend