The built in login controls in Visual studio stores the data entered inside of a SQL (.mdf) database. Does anyone know if it is possible to modify the controls in suck a way to allow them to store the data inside of an Access (.accdb) database?
South Africa’s biggest forum. Discuss, discover, and connect with thousands of members.
Project I'm busy with require the database software use to be access, I would have preferred SQL server due to they tables can be created ect. I found some providers but most of them etheir add too much functionality or don't work correctly.Ok, first question. Why access? You can use sql express instead. The login controls (and ultimately the database schema and so on that the controls need) rely heavily on sql. If you can find a provider that someone has written maybe, but I think you would be out of luck with this one.
using System.Data.OleDB
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Logged"] == "Yes")
{
Response.Redirect("RegMembers.aspx");
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
string stringConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Jet OLEDB:Database Password=MyDbPassword;
OleDbConenction Conn = new OleDbConenction(stringConn);
Conn.Open();
SqlCommand command = new SqlCommand("Select * FROM [COLOR="#FF0000"][table name][/COLOR] WHERE [COLOR="#FF0000"]NickName='" + txtName.Text + "'[/COLOR] AND [COLOR="#FF0000"]Password = '" + txtPass.Text + "'"[/COLOR], Conn);
SqlDataReader rdr = command.ExecuteReader();
string passwordDB_temp = "", user = "", status = "", name = "", p_id = "", game = "";
while (rdr.Read())
{
passwordDB_temp = rdr.GetString(6);
user = rdr.GetString(3);
status = rdr.GetString(5);
name = rdr.GetString(2);
p_id = rdr.GetInt32(0).ToString();
game = rdr.GetString(7);
}
if (passwordDB_temp.Trim() == txtPass.Text.Trim())
{
Session["Logged"] = "Yes";
Session["User"] = user;
Session["Status"] = status;
Session["Name"] = name;
Session["ID"] = p_id;
Session["Game"] = game;
sqlConn.Close();
Response.Redirect("RegMembers.aspx");
}
else
{
sqlConn.Close();
txtLogin.Visible = true;
}
}
catch (SqlException)
{
Response.Redirect("fail.aspx");
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Logged"] == "Yes")
{
}
else
{
Response.Redirect("Default.aspx");
}
if (Session["Status"].ToString() == "Admin")
{
lnkEditAdmin.Visible = true;
}
}
Ipwn 4, glad you came right
Nemesis, your code above is exposed to sql injection attacks. Just remember to encode the input values, you can use HTMLEncode to do that. I keep on forgetting to do that myself, so now I have a sticky note just for reminding me![]()
And yes, because I'm such an amazing person, I'll paste the EXACT CODE YOU NEED!(This is in C#, but you can adapt it to C++). Also, this is MY code, dot taken from any site or anything, so full credit foes to me. Enjoy.
Ipwn 4, glad you came right
Nemesis, your code above is exposed to sql injection attacks. Just remember to encode the input values, you can use HTMLEncode to do that. I keep on forgetting to do that myself, so now I have a sticky note just for reminding me![]()
Crap.. should read the whole thread before posting![]()
Gave me some interesting reading, this question me be as noob as the come but I wouldn't know where to start to find the answer:
In my first attemp I had the oleDbConnections in the code behind each page, this I figured would mean lots op connections being opened and closed and would ultimately result in slow performance. After reading the fineprint I changed my code to make use of methods stored inside of a web service. This however has lead to a performance decrease(not much, less than a sec difference but enough to notice after refreashing a page a few times during testing). So my question is why? Why use a web service when the same can be done in the code behind each page? And why should I use a web service?
I apologize in advance if this question is stupid( I wouldn't know as this is my first website and my college books are a joke)
shogun,
at the place where you work, do you use a lot of L2SQL/EF/NHibernate or more standard T-SQL/stored procedures stuff?
Or find a Linq Access provider - save yourself alot of OleDb pain. Although I don't know if one exists.
Also, although you gain alot of power by writing your own auth, the built in one is pretty good and encompassing (get over it! It really is.). And if you do need more, just override the methods so that you can still use the default controls, but with your code.
Voila.
I'd provide some comments / criticism on your site. BTW - web services are an awesome way of achieving some sort of a SOA in your project. It'll also save you a lot of time later on when you need to build or provide some form of API to your web application. ANOTHER benefit is AJAX-ifying many of your interactions later on. So, plan early and save yourself a lot of time later on.![]()