CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2009
    Posts
    35

    [RESOLVED] Help in Publish Website + ASP.net + C#

    I have currently two forms in mine website..I m also posting their codes--

    FrmRegistration.aspx
    Code:
    public partial class FrmRegistration : System.Web.UI.Page
    {
       
        SqlConnection conn = new SqlConnection("Data Source=SONIA-B408A4159\\SQLEXPRESS;Initial catalog=sonia;Integrated Security=true");
        string query;
        SqlCommand cmd;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSubmit.Attributes.Add("onclick", "Javascript: return Validations() ");
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            query = "Insert into UserInfo values(@name,@email)";
            cmd = new SqlCommand(query, conn);
            conn.Open();
            cmd.Parameters.AddWithValue("@name", txtName.Text);
            cmd.Parameters.AddWithValue("@email", txtEmail.Text);
            cmd.ExecuteNonQuery();
            conn.Close();
            Session["Name"] = txtName.Text; 
            Response.Redirect("FrmUserDetails.aspx");
          
        }
    }

    FRMUSERDERATILS-
    Code:
    public partial class FrmUserDetails : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            lblUserName.Text = "SONIA";
            //lblUserName.Text = Session["Name"].ToString ();
                    
        }
    }
    I publish the website using the foll. steps -
    Code:
    1. go to your root directory (in which your IIS is installed....assuming that you are using winxp sp2 and if you installed ur OS in "C" drive then usually your IIS's root folder does exist in -->"C:\Inetpub\WWWRoot")
    2. Create a new folder there with any name you wish...e.g. TESTSITE for an example
    3. Come back to VS2005 IDE....open your website
    4. Goto "Build" menu and select "Publish Website" option.
    5. Now click on ellipse(...) button and click to select "Local IIS" from the left panel of the dialog box that appears
    6. Expand the "Default Web Site" node...there you can see the folder("TESTSITE") that you just created...Select the folder and click Open (if you see any message click on YES to proceed)
    7. Make sure that the option "Allow this precompiled site to be updateable" is checked
    8. Now click OK....publishment of your site will begin...notice the process in the outout window
    9. If all goes well then you will see a message "Publish succeeded"....this means that you have successfully passed the hardle from VS2005
    I type - http://localhost/testsite/FrmRegistration.aspx
    Form is successfully opened ...
    Suppose I enter sonia in txt name & [email protected] in txtEmail & when i press submit - Error is dere.

    Code:
    Server Error in '/TESTSITE' Application.
    --------------------------------------------------------------------------------
    
    Cannot open database "sonia" requested by the login. The login failed.
    Login failed for user 'SONIA-B408A4159\ASPNET'. 
    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: Cannot open database "sonia" requested by the login. The login failed.
    Login failed for user 'SONIA-B408A4159\ASPNET'.
    
    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.
    When i run my website.by pressing F5,everything is working fine,Can somebody tell me y the error is dere??

  2. #2
    Join Date
    Feb 2005
    Location
    Denmark
    Posts
    742

    Re: Help in Publish Website + ASP.net + C#

    Well - the error message says your user does not have access rights to the database so ..... that's the place to look at.
    Make sure your user has access to the database - or create a user in the database, and use that login information in your connection string.

  3. #3
    Join Date
    Jun 2009
    Posts
    35

    Re: Help in Publish Website + ASP.net + C#

    I have earlier SQL 2005 Express Edition install..I remove it from control panel.But its not completely remove,can somebody tell me how to completely remove it. Cz now I m using SQL Server 2000 ,even if i craete the user & connect to DB using SQL server authentication,I m still getting the same error..My frnd told me to completely uinstall SQL 2005 might solve this errror!!!!!

    Can somebody tell y i m getting the same error even if I connect using SQL authentication???? Is the reason same told by mine frnd!!!

    Tell me one thing more ,Suppose while creating a user , Suppose i give username A & default databse is sonia..& there is also other user named B whose default DB is sardana.

    SO can i use the username A to connect to DB sardana or only username A can be used to connect to DB sardana .




    Mine update Code,Still getting the same Error

    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 FrmRegistration : System.Web.UI.Page
    {
    
        SqlConnection conn = new SqlConnection("Data Source=(local);Initial catalog=sonia;User ID=sonia;Password=sonia;Integrated Security=true");
        string query;
        SqlCommand cmd;
    
        //http://www.daniweb.com/forums/thread213382.html
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSubmit.Attributes.Add("onclick", "Javascript: return Validations() ");
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            query = "Insert into UserInfo values(@name,@email)";
            cmd = new SqlCommand(query, conn);
            conn.Open();
            cmd.Parameters.AddWithValue("@name", txtName.Text);
            cmd.Parameters.AddWithValue("@email", txtEmail.Text);
            cmd.ExecuteNonQuery();
            conn.Close();
            Session["Name"] = txtName.Text;
            Session ["Email"]=txtEmail .Text ; 
            Response.Redirect("FrmUserDetails.aspx");
          
        }
    }
    Last edited by sonia.sardana; August 26th, 2009 at 01:50 PM.

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Help in Publish Website + ASP.net + C#

    Removing SQL Express and using SQL 200 is not the way to solve the problem. IN your code, you were using Windows Authentication and you should know that ASP applications run under ASPNET user account. And your code was internally trying to use this login to connect to the SQL Express. What you needed to do was to create a user in SQL Express, grant the user access to the database "sonia" and then use the username and password to connect to SQL Express database.

    Removing SQL Express does not solve the problem in the code.

    Now coming to your 2nd post, you are using Integrated Security which is supposed to be used with Windows Authentication, remove this from your connectionstring.

    Also take a look at how conenction strings are built for SQL server access on http://www.connectionstrings.com/sql-server-2005 for SQL 2005.

  5. #5
    Join Date
    Jun 2009
    Posts
    35

    Re: Help in Publish Website + ASP.net + C#

    hi I just remove integrated security = true & it worked out..Now i m able to insert the records thru IIS using SQL Authentication.


    Code:
    SqlConnection conn = new SqlConnection("Data Source=(local);Initial catalog=sonia;User ID=sonia;Password=sonia");

  6. #6
    Join Date
    Jun 2009
    Posts
    35

    Re: Help in Publish Website + ASP.net + C#

    Thx for all ur help

  7. #7
    Join Date
    Jun 2009
    Posts
    35

    Re: [RESOLVED] Help in Publish Website + ASP.net + C#

    I have small probs,
    In Registration forr, I m creating a session
    Session["Name"] = txtName.Text;
    After submit user redirect to FrmUserDetails.aspx. On user details form , I have linkSignOut_Click , I want that when the user clicks on it,I want to clear all the sessions. When the user open again http://localhost/mysite/FrmUserDetails.aspx in same browser,I want to redirect the user to Registration form,AS I clear the session. BUt mine code is not redirecting,Y SO ??????

    Code:
    public partial class FrmRegistration : System.Web.UI.Page
    {
    
        SqlConnection conn = new SqlConnection("Data Source=(local);Initial catalog=sonia;User ID=shouvik;Password=sonia");
        string query;
        SqlCommand cmd;
    
        
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSubmit.Attributes.Add("onclick", "Javascript: return Validations() ");
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            query = "Insert into UserInfo values(@name,@email)";
            cmd = new SqlCommand(query, conn);
            conn.Open();
            cmd.Parameters.AddWithValue("@name", txtName.Text);
            cmd.Parameters.AddWithValue("@email", txtEmail.Text);
            cmd.ExecuteNonQuery();
            conn.Close();
            Session["Name"] = txtName.Text;
            Session ["Email"]=txtEmail .Text ; 
            Response.Redirect("FrmUserDetails.aspx");
          
        }
    }


    FrmUserDetails.aspx
    Code:
    public partial class FrmUserDetails : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
           
                if (Session["Name"] != null)
                {
                    lblUserName.Text = "Welcome " + Session["Name"].ToString();
                }
                else
                {
                    Response.Redirect("FrmRegistration.aspx");
                }
                       
           
                    
        }
    
        protected void linkSignOut_Click(object sender, EventArgs e)
        {
            Session.Clear();
        }

  8. #8
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: [RESOLVED] Help in Publish Website + ASP.net + C#

    At first sight I completely misunderstood the post. You are only clearing the session in Click event handler of linkSignOut. The Response.Redirect method is only written in the Load Event handler. You should write the Response.Redirect method in the Click event handler of the linkSignout too.

    By the way, did you debug the code to see why it is redirecting to the previous page?
    Last edited by Shuja Ali; August 27th, 2009 at 12:53 PM. Reason: Corrected the post.

  9. #9
    Join Date
    Jun 2009
    Posts
    35

    Re: [RESOLVED] Help in Publish Website + ASP.net + C#

    Sir I want that suppose when the user logins ,user is redirected to FrmDetails Form....I m running my project on localhost..Now when the user clicks on sign out,I want to clear the session..SO that suppose user types http://localhost/mysite/FrmUserDetails.aspx in the same browser after when he clicks on sign out,I want the user to redirect to Registration form. I m clearing the session values Session.Clear(); on sign out clear,But the values are not clear!!!

  10. #10
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: [RESOLVED] Help in Publish Website + ASP.net + C#

    Well then you should be reading more about Forms Authentication.
    http://msdn.microsoft.com/en-us/library/aa480476.aspx
    http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx
    http://www.devhood.com/Tutorials/tut...tutorial_id=85

    These links have enough material to get you started with forms authentication. This is how you should be handling log-in log-out for your application. using sessions is an old classic ASP technique and has its own drawbacks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured