User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 392,091 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,933 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1252 | Replies: 1
Reply
Join Date: Sep 2007
Posts: 1
Reputation: idiot_ishu007 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
idiot_ishu007 idiot_ishu007 is offline Offline
Newbie Poster

Question how to connect to database

  #1  
Sep 7th, 2007
Hi Everybody
i have been trying to develop a website for my company in asp.net using c# . i have a problem i login page . i am not able to connect it to my database so that i can match user name and password . plz tell me what mistake i am making.
C# CODE

using System;
using System.Data;
using System.Configuration;
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 _Default : System.Web.UI.Page 
{
	protected bool ValidateUser(string userName, string passWord)
	{

		SqlConnection Conn;

		SqlCommand cmd;

		string lookupPassword = null;

		try
		{

			Conn = new SqlConnection("Data Source=xxx;User ID=xxx;Password=xxxx");

			Conn.Open();


			cmd = new SqlCommand("Select pwd from users where uname = '@userName'", Conn);

			cmd.Parameters.Add("@userName");

			cmd.Parameters["@userName"].Value = userName;


			lookupPassword = (string)cmd.ExecuteScalar();


			cmd.Dispose();

			Conn.Dispose();

		}

		catch (Exception ex)
		{


			System.Diagnostics.Trace.WriteLine("[ValidateUser] Exception ");

		}

		if (null == lookupPassword)
		{


			return false;

		}


		return (0 == string.Compare(lookupPassword, passWord, false));

	}
	
}

.aspx CODE

private void cmdLogin_ServerClick(object sender, System.EventArgs e)
    {
        if (ValidateUser(txtUserName.Value, txtUserPass.Value))
        
            FormsAuthentication.RedirectFromLoginPage(txtUserName.Value,
			chkPersistCookie.Checked);
            
        
        else
            Response.Redirect("logon.aspx", true);
    }
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: England
Posts: 153
Reputation: ptaylor965 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 19
Sponsor
ptaylor965's Avatar
ptaylor965 ptaylor965 is offline Offline
Junior Poster

Re: how to connect to database

  #2  
Sep 9th, 2007
It looks like your connection string is at fault

try changing it to this
Data Source=SERVERNAME;Initial Catalog=DATABASENAME;UID=USERNAME;PWD=PASSWORD

from
Data Source=xxx;User ID=xxx;Password=xxxx
Peter Taylor
Visual Basic.NET Application Developer

TaylorsNet
http://www.taylorsnet.co.uk
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 12:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC