View Complete Post
Hello:
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);
when publishing in the webmatrix dialogue it asks for "destination connection string" for my "database.mdf"
I was not sure what it was so I pasted this from my web.config file :
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True it all published ok, but wont run, so I guess it has somthing to do with this connection string or some kind of configuration issue. My question is this, What should go in the field for "Destination connection string"
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\database.mdf;Integrated Security=True;User Instance=True
it all published ok, but wont run, so I guess it has somthing to do with this connection string or some kind of configuration issue.
My question is this, What should go in the field for "Destination connection string"
Hey,
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
Hall of Fame Twitter Terms of Service Privacy Policy Contact Us Archives Tell A Friend