Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > BOOK: Professional ASP.NET 3.5 Security, Membership, and Role Management ISBN: 978-0-470-37930-1
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET 3.5 Security, Membership, and Role Management ISBN: 978-0-470-37930-1
This is the forum to discuss the Wrox book Professional ASP.NET 3.5 Security, Membership, and Role Management with C# and VB by Bilal Haidar; ISBN: 9780470379301
Welcome to the p2p.wrox.com Forums.

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 .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 19th, 2015, 10:36 AM
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 11:42 AM. Reason: Error was not clear
Reply With Quote
  #2 (permalink)  
Old March 19th, 2015, 07:22 PM
Friend of Wrox
Points: 486, Level: 7
Points: 486, Level: 7 Points: 486, Level: 7 Points: 486, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 122
Thanks: 1
Thanked 10 Times in 10 Posts
Default

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 07:26 PM.
Reply With Quote
  #3 (permalink)  
Old March 20th, 2015, 07:27 AM
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

I'm using the connection string that is described in the web.config file but I tried to pass the config file's "MyDB" connection string but that also throws the same error.

These are the connection strings I'm using in my application and declared in web.config file

<connectionStrings>
<add name="BL3DBEntities" 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.EntityClient" />

<add name="ErrorLogDB" 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" />

<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;persist security info=True;user id=sa;password=pwd;multipleactiveresultsets=True;& quot;" providerName="System.Data.SqlClient" />
</connectionStrings>

The MyDB connection string I've specially created for logging the user activity.

Last edited by Priyanka Nellore; March 20th, 2015 at 07:49 AM. Reason: Missed a part of the message
Reply With Quote
  #4 (permalink)  
Old March 20th, 2015, 08:07 AM
Friend of Wrox
Points: 486, Level: 7
Points: 486, Level: 7 Points: 486, Level: 7 Points: 486, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 122
Thanks: 1
Thanked 10 Times in 10 Posts
Default

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
Reply With Quote
  #5 (permalink)  
Old March 20th, 2015, 10:23 AM
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

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 10:27 AM. Reason: missed part of message
Reply With Quote
  #6 (permalink)  
Old March 21st, 2015, 03:02 PM
Friend of Wrox
Points: 486, Level: 7
Points: 486, Level: 7 Points: 486, Level: 7 Points: 486, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 122
Thanks: 1
Thanked 10 Times in 10 Posts
Default

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.
Reply With Quote
  #7 (permalink)  
Old March 21st, 2015, 03:19 PM
Friend of Wrox
Points: 486, Level: 7
Points: 486, Level: 7 Points: 486, Level: 7 Points: 486, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2014
Posts: 122
Thanks: 1
Thanked 10 Times in 10 Posts
Default

as an example for the ErrorLogDB, I don't know all the details of the context so this purely example of entity frame and fetching and adding some data.

Code:


public Logs[] GetLogsBetween(DateTime start, DateTime end )
{
       Logs[] rVal = null;

      using( var db = new ErrorLogDBContext() )
      {
             rVal = db.LogTable.Where( r => r.LogTime >= start && r.LogTime <= end ).ToArray();
      }

      return rVal;
}


public void Log( Log log )
{
        using( var db = new ErrorLogDBContext() )
       {
            db.LogTable.Add(log)
            db.SaveChanges();
       }
}

use between ObjectContext and DBContext are slightly different but for the most part are the same (DBContext consumes an ObjectContext). the illustration above is of a DBContext

Last edited by mmorgan30; March 21st, 2015 at 03:30 PM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing System.Data.SQLClient dll mike_abc VB.NET 2 June 3rd, 2011 10:18 PM
System.Data.SqlClient.SqlDataReader - URGENT wk ASP.NET 2.0 Basics 8 September 27th, 2006 05:00 AM
'SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION' soorsha General .NET 0 September 23rd, 2006 11:59 PM
System.Data.SqlClient.SqlException: Login failed f belete SQL Server 2005 3 May 18th, 2006 08:18 AM
System.Data.SqlClient.SqlException kbarsi Beginning VB 6 2 August 13th, 2005 09:39 PM



All times are GMT -4. The time now is 01:25 AM.


Powered by vBulletin®
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.