Click to See Complete Forum and Search --> : Unable to open connection to the database


hitai
October 29th, 2005, 04:44 AM
In the web application I`m trying to build, there is a form with text boxes on it as a submit button. When the submit button is clicked, the following even handler will execute


private void butangSerah_Click(object sender, System.EventArgs e)
{
this.oleDbConnection.Open ( ) ;

this.oleDbDataAdapter.InsertCommand.CommandText = "INSERT INTO Customers " +
"( IC_no, Username, PasswordText, Name, Gender, Address, telefon, Email, " +
"Occupation ) VALUES ( " + this.nomborKP.Text + "," + this.namaPengguna.Text +
"," + this.kataLaluan.Text + "," + this.nama.Text + "," +
( this.jantina.SelectedValue == "Male" ? true : false ) +
"," + this.alamat.Text + ","
+ this.emel.Text + "," + this.pekerjaan.Text + ")";

this.oleDbDataAdapter.InsertCommand.ExecuteNonQuery ( ) ;
this.oleDbConnection.Close ( ) ;
}

The problem that I`m having is that the line "this.oleDbConnection.Open ( ) ;" throws an OleDbException with the message "The Microsoft Jet database engine cannot open the file 'C:\Inetpub\wwwroot\kedaiCPOnline\bin\onlineCDShop.mdb'. It is already opened exclusively by another user, or you need permission to view its data. "

I`ve tried checking the code and everything and i can`t figure out the problem. Anyone can help? And BTW, nothing else has an open connection to the database. At least none that I know of.

hspc
October 29th, 2005, 05:49 AM
Hi..
1-Does the the ASPNET account have permission to open the file??
2-Does the database have user accounts with passwords or is the DB password protected? If so you'll need to add them to the connection string.

Check the above points and let us know the result..

hitai
October 29th, 2005, 06:27 AM
Thanks for the reply.

1. ASPNET account? Dont`t know wat it is. What is it?
2. No, the database is not password word protected in any way.

This is the first time I`m dealing with ASP.NET actually. So don`t know much. I guess the problem must be with the ASPNET account thingy

hspc
October 29th, 2005, 07:34 AM
ASPNET user account is the user used by ASP.NET requests ..
So the permission assigned to this windows account reflects the permissions allowed to the ASP.NET code being executed..
If you use NTFS..You may need to give permissions to that account to access the MDB file.
for windows 2003..Network Service account is used instead of ASPNET.
Some more info:
http://www.mvps.org/marksxp/WindowsXP/aspdot.php

Shuja Ali
October 29th, 2005, 07:48 AM
Thanks for the reply.

1. ASPNET account? Dont`t know wat it is. What is it?
2. No, the database is not password word protected in any way.

This is the first time I`m dealing with ASP.NET actually. So don`t know much. I guess the problem must be with the ASPNET account thingy
ASP.NET Account If you right click on your MyComputer and Click Manage and expand the Local Users and Groups --> Users, you will see a User account by name ASPNET. check if that account has access to the MDB file you are trying to open connection to.

Second thing I would like to add here is that the Insert query that you are trying to execute is not the best way to execute an Insert Query (especially in web-based applications). This way your database becomes available for SQL Injection attacks. This can be very harmful when you are building big applications that will be used on Internet by lots of users. So to have secure query, you should use Parameterized Query to Insert/Update/Select data from a database. Take a look at how parametrized queries can be created on MSDN.

hitai
October 31st, 2005, 03:51 AM
Thanks for the help. I've got it working now using impersonation

I wil take a look at parametrized queries soon