You are currently viewing the BOOK: Professional ASP.NET 3.5 Security, Membership, and Role Management ISBN: 978-0-470-37930-1 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnectio
I'm trying to record User Activity for my Entity Framework application and when I run my code I'm getting the error "An error occurred while attempting to initialize a System.Data.SqlClient.SqlConnection object. The value that was provided for the connection string may be wrong, or it may contain an invalid syntax. Parameter name: connectionString". The application does not have Username s separately our department has MUD ID's which are hardcoded with the IP address and those MUD ID's automatically get recognized and we get the access to the application its not USERNAME Password giving type. could anybody suggest any solution for this and I'm using Enterprise Library for my project just for your information. Please help
this my UserActivityPage.aspx.cs code
public partial class UserActivityPage : BasePage
protected void Page_Load(object sender, EventArgs e)
base.LogActivity("Visiting the UserActivityPage...", true);
public class BasePage : System.Web.UI.Page
protected void LogActivity(string activity, bool recordPageUrl)
// Get information about the currently logged on user
MembershipUser currentUser = Membership.GetUser(false); // Exception at GetUser function - System.ArgumentException
//MembershipUser currentUser = null;
//currentUser = "bk293393";
if (currentUser != null)
Guid userId = (Guid)currentUser.ProviderUserKey;
// Log the activity in the database
using (SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrin gs["MembershipConnectionString"]
.ConnectionString)) //Exception at Bolded ConnectionString - System.Configuration.ConfigurationErrorsException
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "[dbo].[SP_LogUserActivity]";
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Connection = myConnection;
and in my web.config file I've the following code:
The only connection string that I see, is a connection string for an entity frame work DBConext or ObjectContext but yet, you are trying to instance a new sqlconnection and use sqlcommands and parameters. You are mixing your technologies here. The exception thrown clearly states the connectionstring referenced is not in the proper syntax. Which technology are you trying use?
Last edited by mmorgan30; March 19th, 2015 at 08:26 PM.
All 3 of these connection strings are for entity frame work context. Since the are in the web.cong and typically added when you add an entity model, I am assuming you have models? Why not use the context associated with the connection string and instead of a sqlconnection and sqlcommand
Actually I'm new to entity framework and this project is partly developed by another organization which was transferred to us and I'm trying to do add some features to it...so could you explain me in detail where these models could be and how I can use them instead of sqlconnection and sqlcommand? and this page is not associated with any other tables in the entity model (.edmx file) its just a test I'm trying to do...if its successful I have to include in the remaining pages.
Last edited by Priyanka Nellore; March 20th, 2015 at 11:27 AM.
Reason: missed part of message
I believe that your models are in the app_code folder according to the connection string. Trying doing a search of the entire solution for the work Context until you find a class declarion that either extends an objectcontext or dbcontext.