Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 Search this Thread Display Modes
  #1 (permalink)  
Old October 18th, 2010, 05:27 AM
Authorized User
 
Join Date: Sep 2009
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default about ASPNetDB.mdf

Respected Imar Sir,
Recently I made a website in asp.net , which worked perfectly alright on my local host...then I launch it on live server.

This site is about the hotel, which having its club and I made a form to register as a club member..

for this I made separate folder as ClubMember , In that I have CreateWizard.aspx and CreateWizard.aspx.cs in which I wrote a code for membership form...I have used createWizard control for this membership form...

code in CreateWizard.aspx.cs is
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class ClubMember_CreateNewWizard : System.Web.UI.Page
{
    private void Page_Load(object sender, EventArgs e)
    {

    }
    // CreatedUser event is called when a new user is successfully created
    public void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {

        // Create an empty Profile for the newly created user
        ProfileCommon p = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);

        // Populate some Profile properties off of the create user wizard
        p.Country = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListCountry")).SelectedValue;
        p.Gender = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListGender")).SelectedValue;
        p.Age = Int32.Parse(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtAge")).Text);
        p.Address =(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress")).Text);
        p.City = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtCity")).Text);
        p.Contact1 = Double.Parse(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtContact1")).Text);
        p.Contact2 = Double.Parse(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtContact2")).Text);
        p.AccountType = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtAccountType")).Text);
        p.FirstName = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtFirstName")).Text);
        p.LastName = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtLastName")).Text);
        p.PostalCode = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPostalCode")).Text);
        p.MemberType = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListMemberType")).SelectedValue;
        p.Email = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtEmail")).Text);
        p.CardType = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListCardType")).SelectedValue;
        p.PhotoIDProof = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListPhotoID")).SelectedValue;
        p.PhotoIDNumber = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPhotoIDNumber")).Text);
        p.CardNumber = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtCardNumber")).Text);
        (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtJoin")).Text) = DateTime.Now.ToString();
        p.DateOfJoin = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtJoin")).Text);
        
        Roles.AddUserToRole(CreateUserWizard1.UserName, "ClubMembers");
        lblDateOfJoin.Text = DateTime.Now.ToString();
        
        // Save the profile - must be done since we explicitly created this profile instance
        p.Save();




         SqlConnection conn = null;
        SqlTransaction trans = null;
        SqlCommand cmd;

        try
        {
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Roy"].ConnectionString);
            conn.Open();

            trans = conn.BeginTransaction();

            cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.Transaction = trans;


            //set Reservation details

            cmd.CommandText = "INSERT INTO ClubMembers(FirstName,LastName,Age,MembershipType,DateOfJoin,PhotoIDNo,Contact1,CardNo,EmailID,PhotoIDProof,CardType,Address,City,PostalCode,Country,Contact2)"
                                + "VALUES(@FirstName,@LastName,@Age,@MembershipType,@DateOfJoin,@PhotoIDNo,@Contact1,@CardNo,@EmailID,@PhotoIDProof,@CardType,@Address,@City,@PostalCode,@Country,@Contact2)";

            cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@LastName", SqlDbType.VarChar, 50);

            cmd.Parameters.Add("@DateOfJoin",SqlDbType.DateTime);
            cmd.Parameters.Add("@MembershipType",SqlDbType.NVarChar,50); 
            cmd.Parameters.Add("@PhotoIDNo", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@Age", SqlDbType.Int);
            cmd.Parameters.Add("@Contact1", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@Contact2", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@CardNo", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@EmailID", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@PhotoIDProof", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@CardType", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 255);
            cmd.Parameters.Add("@City", SqlDbType.VarChar, 50);
            cmd.Parameters.Add("@PostalCode", SqlDbType.NVarChar, 50);
            cmd.Parameters.Add("@Country", SqlDbType.VarChar, 50);


            cmd.Parameters["@FirstName"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtFirstName")).Text);
            cmd.Parameters["@LastName"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtLastName")).Text);
            cmd.Parameters["@DateOfJoin"].Value=(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtJoin")).Text);
            cmd.Parameters["@PhotoIDNo"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPhotoIDNumber")).Text);
            cmd.Parameters["@Contact1"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtContact1")).Text);
            cmd.Parameters["@Contact2"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtContact2")).Text);
            cmd.Parameters["@Age"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtAge")).Text);
            cmd.Parameters["@CardNo"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtCardNumber")).Text);
            cmd.Parameters["@EmailID"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtEmail")).Text);
            cmd.Parameters["@PhotoIDProof"].Value = (((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListPhotoID")).Text);
            cmd.Parameters["@MembershipType"].Value=(((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListMemberType")).Text);
            cmd.Parameters["@CardType"].Value = (((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListCardType")).Text);
            cmd.Parameters["@Address"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtAddress")).Text);
            cmd.Parameters["@City"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtCity")).Text);
            cmd.Parameters["@PostalCode"].Value = (((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("txtPostalCode")).Text);
            cmd.Parameters["@Country"].Value = (((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("DropDownListCountry")).Text);

            int MemberID = Convert.ToInt32(cmd.ExecuteScalar());

            trans.Commit(); //commit the transaction
        }

        catch (SqlException SqlEx)
        {
            //some form of error- rollback the transaction
            //and rethrow the exeption
            if (trans != null)
                trans.Rollback();

            // Log the exception
            // Tools.log("An error occurred while executing the transaction", SqlEx)
            throw new Exception("An error Occured while Create Membership", SqlEx);

        }

        finally
        {
            if (conn != null)
                conn.Close();
        }

    }

    
       
       
}
I have a web.config file in ClubMember folder which I gave connection string as (here i m not giving username password for my online db)
Code:
<connectionStrings>
    <add name="Roy" connectionString="Data Source=xx.xxx.xxx.xx;UID=someuid;PWD=somepwd;DATABASE=RoyalH" providerName="System.Data.SqlClient"/>
  
  </connectionStrings>
my RoyalH database is online on SQL server...but my ASPNETDB.mdf database is not on online SQL server, but it is on my FTP...means I moved my App_Data folder on FTP which contains ASPNETDB.mdf.... the above code use both ASPNET.mdf and RoyalH database...

When I do entry on local server(on my PC)...code works finely and respective data goes to RoyalH and ASPNETDB.mdf database, but when I try to fill the membership form online after clicking button, I get following error

Code:
 A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)]
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4846887
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject) +4860189
   System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +90
   System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +376
   System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +221
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +4861315
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +433
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
   System.Data.SqlClient.SqlConnection.Open() +122
   System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context, Boolean revertImpersonate) +87
   System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString, Boolean revertImpersonation) +221
   System.Web.Security.SqlMembershipProvider.CreateUser(String username, String password, String email, String passwordQuestion, String passwordAnswer, Boolean isApproved, Object providerUserKey, MembershipCreateStatus& status) +2430
   System.Web.UI.WebControls.CreateUserWizard.AttemptCreateUser() +318
   System.Web.UI.WebControls.CreateUserWizard.OnNextButtonClick(WizardNavigationEventArgs e) +102
   System.Web.UI.WebControls.Wizard.OnBubbleEvent(Object source, EventArgs e) +418
   System.Web.UI.WebControls.CreateUserWizard.OnBubbleEvent(Object source, EventArgs e) +161
   System.Web.UI.WebControls.WizardChildTable.OnBubbleEvent(Object source, EventArgs args) +19
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
I am not understanding and not able to find solution , when I googled all answer I get is regarding Remote connection in SQL Server..which is correct in my SQL server.
Is there any need to do with my ASPNETDB.MDF database or is any other problem is there??

Please help,

Thanks in advance
Sushant
Reply With Quote
  #2 (permalink)  
Old October 18th, 2010, 05:36 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi there,

Since this is not directly related to my book, would you mind moving this post to a more general ASP.NET category here: http://p2p.wrox.com/asp-net-3-5-436/

This way, others can join, and learn from the discussion as well.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old October 18th, 2010, 10:56 AM
Authorized User
 
Join Date: Sep 2009
Posts: 31
Thanks: 6
Thanked 0 Times in 0 Posts
Default

ok Imar sir,
I understood why you didn't answer my question this time as I made a mistake again...
As you said...I have posted my post in asp.net 3.5 basics forum...I think this is the correct forum for my question..the link is

about ASPNetDB.mdf

and I promises that from next time I will add my post at appropriate position....

I hope I will get correct answer there too...as you always give...

Thanks in advance,
Sushant
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
How to integrate ASPNETDB.MDF dapedley BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 August 9th, 2010 04:05 AM
ASPNETDB.mdf again Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 April 28th, 2009 04:30 PM
ASPNETDB.mdf Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 April 27th, 2009 01:07 PM
ASPNETDB.MDF Changing motemape BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 May 27th, 2007 06:14 AM
aspnetdb.mdf Jackxxx ASP.NET 2.0 Basics 0 January 9th, 2007 01:37 PM



All times are GMT -4. The time now is 08:06 AM.


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