Click to See Complete Forum and Search --> : ASP.Net Database Connectivity


srividya_m
June 17th, 2009, 03:19 AM
Hii friends,

I need to create an application in ASP.net,in which first page contains username,password verification with database.

Database should be oracle 10g,or SQL server2005.

Can anybody help me??

Thank you.

eclipsed4utoo
June 21st, 2009, 11:17 PM
well, you need to know which one it is, because they will use different libraries.

you will want to look into ADO.Net. I personally use the SqlConnection, SqlCommand, and SqlDataReader classes when communicating with a database.

Or, I use LINQ-to-SQL.

srividya_m
June 22nd, 2009, 12:00 AM
HI,
Thank u for reply.Can u give me in detail reply,for my query ,Since i am very new to .net

Can u tell me how to get SQL server authentication while creating data base.

thank u.

kvwarun
July 31st, 2009, 10:55 AM
SQL server provides two type of authentications, first one and default is windows authentication in which SQL server takes current windows login. Second option is SQL server authentication, here you have to specify the exact user name and password which you created in SQL Server.

C# code



using System.Data.SqlClient;

SqlConnection myConnection;
DataSet mDs = new DataSet();
SqlDataAdapter mAd;

myConnection = new SqlConnection("Server = ServerName; Database = DB1; User ID = sa; Password = ******; Trusted_Connection = False;");


mAd = new SqlDataAdapter("SELECT * FROM LOGIN WHERE USERID = @USERID AND PASWD = @PASWD", myConnection);
mAd.SelectCommand.Parameters.Add("@USERID", SqlDbType.Int);
mAd.SelectCommand.Parameters.Add("@PASWD", SqlDbType.Char, 20);
mAd.SelectCommand.Parameters["@USERID"].Value = Text1.Text; // this is the text box which takes user name & second one is password
mAd.SelectCommand.Parameters["@PASWD"].Value = Text2.Text;
mAd.Fill(mDs, "LOGIN");
if (mDs.Tables["LOGIN"].Rows.Count > 0)
{
FormsAuthentication.RedirectFromLoginPage(Text1.Text, false);
}