View Single Post
  #1 (permalink)  
Old March 19th, 2015, 11:36 AM
Priyanka Nellore Priyanka Nellore is offline
Registered User
Points: 62, Level: 1
Points: 62, Level: 1 Points: 62, Level: 1 Points: 62, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2015
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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

namespace BasePage
{
public partial class UserActivityPage : BasePage
{


protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
base.LogActivity("Visiting the UserActivityPage...", true);
}
}
}

public class BasePage : System.Web.UI.Page
{
protected void LogActivity(string activity, bool recordPageUrl)
{
if (Request.IsAuthenticated)
{
// Get information about the currently logged on user
//BL3Helper.GetSession(BL3Session.LOGGEDUSERNAME);

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;
myCommand.Parameters.AddWithValue("@USER_CD", BL3Session.LOGGEDUSERNAME);
myCommand.Parameters.AddWithValue("@Activity", activity);
if (recordPageUrl)
myCommand.Parameters.AddWithValue("@PageUrl", Request.RawUrl);
else
myCommand.Parameters.AddWithValue("@PageUrl", DBNull.Value);
myConnection.Open();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
}
}
}
}

}

and in my web.config file I've the following code:

<add name="MyDB" connectionString="metadata=res://*/App_Code.BL3DBModel.csdl|res://*/App_Code.BL3DBModel.ssdl|res://*/App_Code.BL3DBModel.msl;provider=System.Data.SqlCl ient;provider connection string=&quot;Data Source=server_name;Initial Catalog=DBname;user id=sa;password=pwd;Persist Security Info=False;Integrated Security=False;MultipleActiveResultSets=True&quot; " providerName="System.Data.SqlClient" />

<buildProviders>
<add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesig nerBuildProvider" />
</buildProviders>
</compilation>
<membership defaultProvider="CustomizedProvider">
<providers>
<add name="CustomizedProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MyDB"
applicationName="/" />
</providers>
</membership>
</system.web>

Last edited by Priyanka Nellore; March 19th, 2015 at 12:42 PM. Reason: Error was not clear