|
I am trying to bind the data to Datagrid in ASP.NET web application. My database “AddressBook” is created in MS Access 2000.
I used ‘OleDBConnection’ control and set ‘ConnectionString’ property referring to my MS Access database.
I have written following code in the ‘Page_Load’ method,
private void Page_Load(object sender, System.EventArgs e)
{
OleDbCommand oleCommand = new OleDbCommand();
oleCommand.CommandText="Select * from ADDRESSDATA";
oleDbConnection1.Open();
oleCommand.Connection=oleDbConnection1;
OleDbDataReader oleDataReader = oleCommand.ExecuteReader();
DataGrid1.DataSource=oleDataReader;
DataGrid1.DataBind();
oleDbConnection1.Close();
}
Code compiles successfully, but it following error during execution:
“The Microsoft Jet database engine cannot open the file 'C:\Manisha\Address MS Access Data\AddressBook.mdb'. It is already opened exclusively by another user, or you need permission to view its data.”
Ms Access Database I am using is not open and no other application uses that database.
What’s wrong in this application. Can anyone suggest something please?
Thanks
|
|
|
|
|
one thing, u have to grant permission of asp.net account to AddressBook.mdb
<< >>
|
|
|
|
|
thanks for reply...but how should i do this? is there any specific property to set? pls let me know
|
|
|
|
|
now I cannot remember excactly what steps need to do.
but u can try as:
- right-click on the folder that contains the .mdb file
- In Security tab, add asp.net account and remeber to add Write permission for asp.net account
Hope this helps
<< >>
|
|
|
|
|
hello, thanks for reply, but it is not clear to me how to progress, what do you mean by ASP.NET account? whaere i hv to specify it? I would be glad if ui let me know more deails?
|
|
|
|
|
hi there,
default, ASP.NET account is created when installing asp.net. u can see this by browsing to computer managerment >> Local Users and Groups
this account has limited rights, so u have to grant permission for this account to access ur DB file
<< >>
|
|
|
|
|
I am trying to change a schema of dataset. What I need to do is to change a column type from int to string. I did that in the .xsd file, saved the changes and ran the customer tool (xsd.exe). But strangely the generate cs file does not reflect the change. The column type is still integer. As expected the sqldataadapter fill function does not work.
Any ideas why this happened?
|
|
|
|
|
Compared to a virtual folder, how slow is retrieving and displaying an image from a database compared to retrieving and displaying an image, both on a webpage.
I've currently switched to a mechanism to store images for a webpage in a database rather than a file system because of the hassle of maintaining folders of images that change often, it just removed a lot of work by being able to place the images in the database.
|
|
|
|
|
dear Mackay !
if it possible for you to write your e_mail , for send my application about user and password and ... for you .
my e_mail :nasim476@yahoo.com
thanks for everything !
mostafa hosseiny b.
-- modified at 12:49 Tuesday 6th September, 2005
|
|
|
|
|
First of all, why is it that so many people can't understand what the 'email' link is for ? Secondly, if you have a problem, why don't you ask more questions here ? You're lucky enough that people spend their time giving you free help online without asking to invade their inbox.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Could someone clear up a possible memory leak for me? In using ADO.NET in MFC Projects it is written:
#pragma push_macro("new")
#undef new
try
{
m_OleDbConnection = new OleDbConnection(
S"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\test.mdb"
);
m_OleDbConnection->Open(); // Open up the connection
m_OleDb = new OleDbCommand(S"select * from Persons", m_OleDbConnection);
m_Reader = m_OleDb->ExecuteReader();
int count = 0;
while (m_Reader->Read())
{
AddToList(count,m_Reader->get_Item("First Name")->ToString(),
m_Reader->get_Item("Last Name")->ToString(),
m_Reader->get_Item("Phone Number")->ToString()
);
count++;
}
}
catch(Exception *e)
{
AfxMessageBox(CString(e->ToString()));
}
__finally
{
m_Reader->Close();
m_OleDbConnection->Close();
}
#pragma pop_macro("new")
What is bothering me is there is a new with no delete. The most surprising one is m_OleDb which doesn’t even have a close, let alone a delete. I tried adding a close as well as a delete and neither was accepted by the compiler.
I open and close the database hundreds of times, so I wanted to consider leaving it open and then I started to think about the memory leak problem.
Can anyone give me a hint why a memory leak doesn’t seem to play here?
Thanks,
Ilan
|
|
|
|
|
You need to look up on Garbage Collection in .NET. Basically, there is an entity called the Garbage Collector (GC) that runs in a background thread. It does the cleanup for you, when it determines that a cleanup needs to be done. In your case, when the GC decides to run, if it sees that there are no live references to OleDbConnection and OleDbCommand objects, it will reclaim the memory.
In other words, you can't explicitly delete, as in C++, the GC will (attempt) do it when it decides to. The Close method is to release resources held up by the object, OleDbConnection has Close because it wraps a database connection, but OleDbCommand is just an abstraction for a SQL command, so that's why it doesn't have Close. Calling Close has nothing to do with GC, though.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
ERm.... given that his code contains ->, I'd say it's C++ and not C#
Oh, it's MC++, because he's using .NET objects.
Christian Graus - Microsoft MVP - C++
-- modified at 17:49 Tuesday 6th September, 2005
|
|
|
|
|
I have a problem: I can not get default column value in ADO.NET:
I have a sample table
create table
testtable(id int identity(1,1) not null,
notnullcolumndef5 int not null default (5))
column [notnullcolumndef5] can not be null and has a default value of 5.
now goto VStudio, I use c#, but it does not matter, generate a simple SqlDataAdapter with
select * from testtable
We will use untyped dataset. so
ourSqlDataAdapter.FillSchema(ourUntypedDataSet, SchemaType.Source, "testtable")
this statement fills testtable schema. If you look then in columns collection, our [notnullcolumndef5] column has DefaultValue property set to System.DBNull. WHY ? Where is 5 ?
I think that I simply do not understand something, as fas for such a common problem I did not find any articles. please help !
|
|
|
|
|
|
Thanks ! Right..
I have understood it already on my own. A good example is DATETIME() default - it can not be returned as value, as far as it is insetion time into DB. Of other cases, that can be server-dependent. So - it's right that the field is not filled.
|
|
|
|
|
Hello,
I want to restore an in used SQL Database(via SQL-Script), but is anyone connected with then Database, I can´t restore the Database.
Please help me!!!
|
|
|
|
|
Can you be a bit more explicit of your needs ?
|
|
|
|
|
Its easy to achieve this using SQL DMO. You can expllicitly kill all the existing connections.
But if you are using SQL script then use the following SP
se master
go
--Type procedure
--author mak mak_999@yahoo.com
--date written 4/19/2000
--project maintenance
--objective procedure to kill process for a given database
create procedure usp_killprocess @dbname varchar(128) as
set nocount on
set quoted_identifier off
declare @kill_id int
declare @query varchar(320)
declare killprocess_cursor cursor for
select a.spid from sysprocesses a join
sysdatabases b on a.dbid=b.dbid where b.name=@dbname
open killprocess_cursor
fetch next from killprocess_cursor into @kill_id
while(@@fetch_status =0)
begin
set @query = "kill "+ convert(varchar,@kill_id)
exec (@query)
fetch next from killprocess_cursor into @kill_id
end
close killprocess_cursor
deallocate killprocess_cursor
--usage
--exec usp_killprocess "mydatabasename"
Source: http://www.killersites.com/mvnforum/mvnforum/viewthread?thread=2240
|
|
|
|
|
hellow to all ..
how can i change the tabel titels in the datagrid ...
i have a tabel in the database , and it have names ...
i wana change it name's to what i wana to ..
how can i do it ?
thxx a lott ..
|
|
|
|
|
Change them in the html of the web form by specifing the header text in BoundColumn
example :
<asp:BoundColumn DataField="ded_dte" SortExpression="Date" HeaderText="Date">
<HeaderStyle Width="66px"></HeaderStyle>
</asp:BoundColumn>
-- modified at 4:56 Tuesday 6th September, 2005
|
|
|
|
|
Assuming you are using Windows DataGrid and you want to change the 4th column header
this.yourDataGridTableStyle.GridColumnStyles[3].HeaderText = "Anonymous";
|
|
|
|
|
hi!
I have 2 form and 2 sql table :
the following fields are for 2 table :
table 1 :
id_user type[int],username type[nvarchar],password type[nvarchar]
table 2:
id_name type[int],name type[nvarchar],telephone type[decimal]
//-----
after the user enter his username and password , if it's correct , the second form show the private information .
Now I want to add,delete,save the User private information , in how ,every user enter his
username and password ,show his private info .
How can it possible?
//---------------------
in btnOK_Click Event ,for affirmative user and password is Here :
*************************
private void btnOK_Click(object sender, System.EventArgs e)<br />
{<br />
if ((txtUserName.Text.Trim().Length == 0)|| (txtPassword.Text.Trim().Length == 0))<br />
{<br />
MessageBox.Show(Empty_MESSAGE,CAPTION_TITLE);<br />
txtPassword.Text="";<br />
txtUserName.Text="";<br />
return;<br />
}<br />
string strFilter;<br />
strFilter = "SELECT UserName,Password FROM User_Name WHERE Password='" +txtPassword.Text + "' AND UserName='"+txtUserName.Text+"'";<br />
userAdapter=new SqlDataAdapter(strFilter,UserConnection);<br />
SqlCommandBuilder UserCmd=new SqlCommandBuilder(userAdapter);<br />
DataTable UserTable=new DataTable();<br />
userAdapter.Fill(UserTable);<br />
UserView = new DataView(UserTable,DEFAULT_FILTER,DEFAULT_SORT,DataViewRowState.OriginalRows);<br />
if (UserView.Count == 0)<br />
{<br />
MessageBox.Show(NO_RECORDS_FOUND_MESSAGE,CAPTION_TITLE);<br />
txtPassword.Text="";<br />
txtUserName.Text="";<br />
}<br />
else<br />
{<br />
this.Hide();<br />
Private_Public_Form frm_pub_pri=new Private_Public_Form();<br />
frm_pub_pri.ShowDialog();<br />
}<br />
<br />
}<br />
***********************************************<br />
thanks in advance!!!<br />
<br />
<br />
mostafa hosseiny b.
|
|
|
|
|
manije wrote:
strFilter = "SELECT UserName,Password FROM User_Name WHERE Password='" +txtPassword.Text + "' AND UserName='"+txtUserName.Text+"'";
This is NOT how I showed you to build this query[^]. This is now vulnerable to a SQL Injection Attack, and one that is very easily prevented. Please re-read the code I sent you before and if you don't understand it, I'll be happy to answer questions.
If you want to read more about how to prevent SQL Injection attacks. Something that is very important and double importance seing as this is verifying user names and passwords then you should read SQL Injection Attacks and Tips on How to Prevent Them[^]
Finally, just as an example of how easy your code is to attack I would suggest you type the following into the password box and trace through the code to see what it does:
' OR 1=1;--
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Hi !
thanks for your guide !
but ,I don't understand ,OR,
I want to know , How can observe a user his private information , After everyone enter his username and password .
by the way , the code I wrote,can chech , is there user in the table or not ,in any case ,please help me !
thanks again!
mostafa hosseiny b.
|
|
|
|