Connection command in Access?

Z

ZET

My file menu doesn't have the Connection command - how do I get it as I need
to connect to the Access database from a .NET project?
 
D

Douglas J. Steele

Wouldn't you be connecting TO the Jet database FROM the .Net project, so
you'd be looking in .Net to do this?
 
B

Brendan Reynolds

The Connection command exists in an ADP, not in an MDB, but as Doug suggests
elsewhere in this thread it is not clear how this would help you with your
..NET project. To connect to an Access (more accurately Jet) database from a
..NET project you use ADO.NET and the OLEDB provider. Here's an example I
created to answer another question recently ...

using System;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApplication6
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0" +
";Data Source=C:\\Documents and Settings\\Brendan Reynolds\\" +
"My Documents\\db1.mdb" +
";Persist Security Info=False";
OleDbConnection Connection = new OleDbConnection(ConnectionString);
string SQL = "UPDATE tblTest SET TestText = ?, TestNumber = ? " +
"WHERE TestID = ?";
OleDbCommand Command = new OleDbCommand(SQL, Connection);
OleDbParameterCollection Parameters = Command.Parameters;
Parameters.Add("Param1", OleDbType.Char, 0);
Parameters.Add("Param2", OleDbType.Integer, 0);
Parameters.Add("Param3", OleDbType.Integer, 0);
Parameters["Param1"].Value = "A Test";
Parameters["Param2"].Value = 9;
Parameters["Param3"].Value = 23;
try
{
Connection.Open();
Console.WriteLine(Command.ExecuteNonQuery().ToString());
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
finally
{
if (Connection != null)
{
if (Connection.State != ConnectionState.Closed)
{
Connection.Close();
}
}
}
}
}
}
 
Z

ZET

I did the whole connection object thing in .NET< but get the following error:
The Microsoft Jet database engine cannot open file xx.mdb. It is already
opened exclusively by another user, or you need permission to view this data.
I therefore thought that I need to set some permissions in the Access db?
 
D

Douglas J. Steele

What permissions do you have on the folder where the database exists (or,
more precisely, what permissions are associated with the security context in
which your program runs)?

You need Change on the folder. That's because the first user in creates a
locking file (.ldb) in the folder, subsequent users update the file, and the
last user out deletes it.
 
Z

ZET

Thanks a mil!


Douglas J. Steele said:
What permissions do you have on the folder where the database exists (or,
more precisely, what permissions are associated with the security context in
which your program runs)?

You need Change on the folder. That's because the first user in creates a
locking file (.ldb) in the folder, subsequent users update the file, and the
last user out deletes it.
 
Top