473,413 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Open connection to MS Access Database

Hi Crocrew et. All,

So far everything is working fine however, I want more security by adding a Username: Admin and Password: Test to my MS Access Database. I have 2 separate databases on my server and used two different methods to open a connection to my databases. Like I said, everything works fine without the username and password. I have searched around the internet and tried different sernarios but they don't seem to work anymore. Can you help please?

1st Method: To connect to the MOPsCentral.mdb database.

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")

Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("MOPsCentral.mdb")

2nd Method: To connect to the PTSystem.mdb database.

Function GetConnection()
dim Conn: Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.open "Data Source=" & Server.MapPath("PTSystem.mdb")
set GetConnection = Conn
End function
Jan 31 '08 #1
15 3387
CroCrew
564 Expert 512MB
Hello hotflash,

Someone that is more proficient in Microsoft Access needs to step up and help out on this one. I am a Microsoft SQL Server brat but I know just the right amount to be dangerous in Access. But, I will try to give it a shot.

What I think you are trying to do is lockdown your Access database so that a password has to be passed in via the connection string to gain access to the database.

Solution:
Start Microsoft Access. Close all open databases. Open your database by selecting [File] option from to top toolbar. From the dropdown subset menu select the [Open] option. An Open window dialog will pop up. Browse to your database within this new open window dialog (but do not open it). After you have found your database highlight it by selecting it. At the bottom right of the current open window dialog your will see the [Open] button. Within and to the right of the [Open] button your will notice a [down arrow]. Select this [down arrow] to see an open subset menu. Select the [Open Exclusive] option.

Now that we have our database opened exclusively we can add a password to it. Select the option [Tools] from the top toolbar. From the subset menu hover over the option [Security] and select the option [Set Database Password]. A new set database password window will pop up with two textboxes. For this example in both textboxes enter “happy” (lower case and without the quotes) and click the [OK] button. Close Microsoft Access now completely now.

We are done with the database. Let’s look at our coed now. Try this code to access your database now:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set Conn = Server.CreateObject("ADODB.Connection")
  3.     Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Relative path to your Access database ") & "; Jet OLEDB:Database Password=happy"
  4. '    "DRIVER={Microsoft Access Driver (*.mdb)}; Database Password=happy; DBQ=" & Server.MapPath("Database/Database.mdb") 
  5.     Set rsList = Server.CreateObject("ADODB.Recordset")
  6.     SQL = "SELECT * FROM YourTable"
  7.     rsList.CursorType = 1
  8.     rsList.LockType = 3
  9.     rsList.Open SQL, Conn
  10. %>
  11.  
  12.  
If you’re really looking to be more secure then I would suggest to upsize your Access database to something like Microsoft SQL Server.

Hope this helped you out~
Jan 31 '08 #2
Hi CroCrew,

Sorry that I missed one more portion on the second part of the Open connection. I have to use this type of strange format because I have to attach the file along with the record submission as well. I got the source code from
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8225&lngWId=4 that's why i have to stick with their format for now.

Thanks and please help.


Function OpenUploadRS()
Dim RS : Set RS = CreateObject("ADODB.Recordset")

'Open dynamic recordset, table Upload
RS.Open "PTSProjects", GetConnection, 2, 2

Set OpenUploadRS = RS
End Function

Function GetConnection()
dim Conn: Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
Conn.open "Data Source=" & Server.MapPath("PTSystem.mdb")
set GetConnection = Conn
End function
Feb 1 '08 #3
CroCrew
564 Expert 512MB
Hello hotflash,

Can you do this (that is after adding a password on your database as in the example above)?


Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Function GetConnection()
  3.     Set Conn = Server.CreateObject("ADODB.Connection")
  4.         Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Relative path to your Access database ") & "; Jet OLEDB:Database Password=happy"
  5.         set GetConnection = Conn
  6.     End function
  7. %>
  8.  
  9.  
Feb 1 '08 #4
Hi CroCrew,

YOU ARE THE BEST. The 2 recommendations that you provided above worked fine. I have one more format that I got and wonder if you can help as well. Thanks for your help.

<%
set objconn=server.createobject("adodb.connection")
connpath="DBQ=" & server.mappath("PTSystem.mdb")
objconn.Open "DRIVER={Microsoft Access Driver (*.mdb)}" & connpath
set objrs=objconn.execute("select * from PTSProjects")
%>
Feb 2 '08 #5
CroCrew
564 Expert 512MB
Hello hotflash,

Can you give us a bit more information on what you are trying to do and what errors if any that you are getting?


Thanks~
Feb 2 '08 #6
Hi CroCrew,

I want to put a password protect on my database like the previous 2 examples you gave me. I am getting Internal Error. Since the database is password protected, how can you modify the code below to make it work with a Database Password? Thanks for your outstanding support.

<%
set objconn=server.createobject("adodb.connection")
connpath="DBQ=" & server.mappath("PTSystem.mdb")
objconn.Open "DRIVER={Microsoft Access Driver (*.mdb)}" & connpath
set objrs=objconn.execute("select * from PTSProjects")
%>
Feb 3 '08 #7
CroCrew
564 Expert 512MB
Hello hotflash,

Try this code over that code:

Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Set Conn = Server.CreateObject("ADODB.Connection")
  3.         Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Relative path to your Access database ") & "; Jet OLEDB:Database Password=happy"
  4.         Set objrs = Server.CreateObject("ADODB.Recordset")
  5.         SQL = "select * from PTSProjects"
  6.         objrs.CursorType = 1
  7.         objrs.LockType = 3
  8.         objrs.Open SQL, Conn
  9. %>
  10.  
  11.  
Feb 3 '08 #8
Hi CroCrew,

Thanks for your help but I still can't export the table to Excel after I put the password protect on the database. Below is the ORIGINAL code that I used and worked fine before I put the password on the Database.

I got this code from the Internet. Thanks.

<%
Response.ContentType = "application/vnd.ms-excel"
%>

<%
set objconn=server.createobject("adodb.connection")
connpath="DBQ=" & server.mappath("PTSystem.mdb")
objconn.Open "DRIVER={Microsoft Access Driver (*.mdb)}" & connpath
set objrs=objconn.execute("select * from PTSProjects")
%>
<TABLE BORDER=1>
<TR>
<%
'Loop through each Field, printing out the Field Names
For i = 0 to objrs.fields.count - 1
%>

<TD><% = objrs(i).name %></TD>
<% next %>
</TR>
<%
'Loop through rows, displaying each field
while not objrs.eof
%>
<TR>
<% For i = 0 to objrs.fields.count - 1
%>
<TD VALIGN=TOP><% = objrs(i) %></TD>
<% Next %>

</TR>
<%
objrs.MoveNext

wend

objrs.Close
objconn.close
%>
Feb 4 '08 #9
CroCrew
564 Expert 512MB
Hello hotflash,

Here is your code. Copy and paste it over yours and it should work.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set Conn = Server.CreateObject("ADODB.Connection")
  3.     Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("PTSystem.mdb") & "; Jet OLEDB:Database Password=happy"
  4.     Set myRS = Server.CreateObject("ADODB.Recordset")
  5.     SQL = "select * from PTSProjects"
  6.     myRS.CursorType = 1
  7.     myRS.LockType = 3
  8.     myRS.Open SQL, Conn
  9. %>
  10. <html>
  11.     <head>
  12.         <title>Example</title>
  13.     </head>
  14.     <body>
  15.         <%Response.ContentType = "application/vnd.ms-excel"%>
  16.         <table border="1">
  17.             <tr>
  18.                 <%For Each Field In myRS.Fields%>
  19.                     <td><%Response.Write(Field.name)%></td>
  20.                 <%Next%>
  21.             </tr>
  22.             <%Do Until (myRS.EOF)%>
  23.                 <tr>
  24.                     <%For i = 0 to myRS.fields.count - 1%>
  25.                         <td><%Response.Write(myRS(i))%></td>
  26.                     <%Next%>
  27.                 </tr>
  28.                 <%myRS.MoveNext%>
  29.             <%Loop%>
  30.         </table>
  31.     </body>
  32. </html>
  33.  
Hope this helps~
Feb 4 '08 #10
Hi Master CroCrew,

You are TRULY A HERO on this forum. Everything works FINE. Questions for you.

1. How can I remove let's say a field called WorkDescription when it is
EXPORT to a file or view?

2. Since you are so good at the ASP stuff, do you know of any script out there that will allow you to generate reports such as:

a. Number of projects opened per month for example 1/1/2008 to
1/31/2008?
b. Display the report in sometype of charts?

Thanks once again for your outstanding support.
Feb 4 '08 #11
CroCrew
564 Expert 512MB
Hello hotflash,

I would not suggest “removing” the record from your database. What I would do if it were me is again; create another field within your database (yes/no) that you can set to know if the data has been “EXPORT”ed to not show up again if the report were to be ran again. I don’t like to “Delete” data till I know for 100% I don’t ever need it again (and that is rare). So, where you’re building your report check to see if this new flag (yes/no) has been set.

As for charting…

I have only used two solutions to do my charting and both I had to pay for.

http://www.simplechart.net/AspChart.aspx?id=40

http://www.dundas.com/

Let me know if I can provide more help~
Feb 4 '08 #12
Hi CroCrew,

Thanks for your information. I have noticed that most of your code has the following:

myRS.CursorType = 1
myRS.LockType = 3

You have a trick where let's say, If I have a project open and getting ready to make the update, and whoever comes behind me can't update it until I am done and out of the record? Thanks.
Feb 4 '08 #13
CroCrew
564 Expert 512MB
Hello hotflash,

A trick? Well, not an easy one. You could add fields to your database that you could check to see if someone has the record checked out.

What comes to mind are fields like:
{Name of Field}, {Data Type}
IsCheckedOut, (Yes/No)
CheckedOutBy, Text
TimeCheckedOut, Date/Time

This way you can know if the recorded is being used and buy whom it is used by and when they checked it out.

Hope that starts the thought process~
Feb 4 '08 #14
Hi CroCrew,

As always, when it comes to ASP, I think you are the best of all bests. This sounds very interesting. I can't believe we can do this using ASP. We used to use a MS Excess as file sharing on the server. Each time when there is a user opens the file, and a second person comes in, he/she can't save to the file because of a first user already had it opened either to view or edit.

I have moved it to a website, I created a search feature like: A (search for file A), and B (search for file B). Let's say when file A is searched, it will display the file A name, and you can either View or Edit. The file for this is DisplayFile.asp.

What do I need to put in the DisplayFile.asp, or EditFile.asp to make it lock the file so others won't be able to view or update it? Thanks for your help.
Feb 5 '08 #15
CroCrew
564 Expert 512MB
Hello hotflash,

It seems like the original question you had has been resolved with the help of this site.

Can you post a new question so that the “title” reflects what your asking help for?

This helps in keeping the thread short and makes for easier searching on this site for *like* answers/solutions.

Thanks~
Feb 5 '08 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Dave | last post by:
I reinstalled SQL 2000 server after reformatting my drive. Now I cannot open a database in my C## program as before. If I use "Provider=SQLOLEDB;Data Source=localhost; Initial...
4
by: Macca | last post by:
Hi, I have an windows forms application that accesses a SQL database I have a few questions as to connecting to the database. This application will run 24 hours a day. It is a monitoring...
4
by: mescano | last post by:
I am currently implementing a singleton pattern for accessing a database. Is it advisable to close the connection to the database at all -- thus leaving it open or should it be closed. If closed,...
2
by: AS | last post by:
Hi, I have a C# windows desktop application that will be used only by one user at a time. The database server (SQL Server 2000) also resides on that machine only. This application has three...
0
by: gm | last post by:
Immediately after generating the Access application from the Source Safe project I get: "-2147467259 Could not use ''; file already in use." If Access database closed and then reopened I get:...
2
by: Gary | last post by:
If you develop a stand alone c# windows application that only reads from a single local Access database, do you need to close the connection each time you navigate to a different record? No other...
6
by: Mike | last post by:
We are intermitantly receiving this error on our website. ExecuteReader requires an open and available Connection. The connection's current state is connecting. Following is the code from the Load...
7
by: fniles | last post by:
I am using VB.Net 2003 and MS Access (connecting using OleDBConnection). I read using DataAdapter and DataSet, not DataReader. When many people try to access the database at the same time, I get...
6
by: =?Utf-8?B?RyBIdXN0aXM=?= | last post by:
I am creating a new MS Access DB in code, which works fine. I then try to open it & set a password. I keep getting an error that the DB is already open by my machine's Admin account. In reality it...
2
by: user | last post by:
Hello, I simply make some aspx web page to update data in a mdb access database..But when this database is open (not table, juste the mdb in access) with MS Access, i have an error with my asp.net...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.