Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell trouble connecting to Access table

Posted on 2012-03-14
7
Medium Priority
?
1,144 Views
Last Modified: 2012-03-16
I'm having trouble connecting to a Table held in a Microsoft Access DB by using Powershell as the language to connect. The issue comes into play by the uid and pwd commands. This is what is causing the issue. If I were to issue the command without the uid and pwd commands, it works successfully but requires that you manually put in the username and password through a prompt which pops up. Problem being is that once this is done I want the script to run as a scheduled task in the middle of the night when no one will be here to type in the username and password.

What am I doing wrong to pass these credentials to the program?

## Create our object to access Access Table
$dataSource = "<.mdb file location>"
$strQuery = "SELECT * FROM table"
$dsn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$dataSource;uid=<username>;pwd=<password>;"

## create connection object and open the database
$objConn = New-Object System.Data.OleDb.OleDbConnection $dsn
$objCmd  = New-Object System.Data.OleDb.OleDbCommand $strQuery,$objConn
$objConn.Open()

## get query results, populate data-adapter, close connection
$adapter = New-Object System.Data.OleDb.OleDbDataAdapter $objCmd
$dataset = New-Object System.Data.DataSet
[void] $adapter.Fill($dataSet)
$objConn.Close()

Open in new window

After that I just use the $dataset.Tables[0].Rows to retrieve data. But besides the point. As I stated earlier, the code works fine if the uid and pwd commands are not used.

Here's the error message when they are used:

Exception calling "Open" with "0" argument(s): "Could not find installable ISAM."
At <script location>:56 char:14
+ $objConn.Open <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
 
Exception calling "Fill" with "1" argument(s): "Could not find installable ISAM."
At <script location>:61 char:21
+ [void] $adapter.Fill <<<< ($dataSet)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Open in new window

An important factor to consider: This Access DB is using linked tables to a Pervasive DB. So the credentials are not to authenticate to Microsoft Access Table/DB, but rather to access the DB on the other server.

***Do not ask why it is done this way, nor suggest that the connection be directly to the Database rather than to a linked file. This was give careful consideration previously.***
0
Comment
Question by:Alex_MPM
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 37724672
Hi
a working example  has been posted here, and the artical contains links to a few good sources.

http://skatterbrainz.blogspot.com/2009/05/using-powershell-with-ms-access.html

Let me know if this helps


Joe

ps   why it is done this way,? thought of  connecting  directly   :-o
0
 

Author Comment

by:Alex_MPM
ID: 37724748
Problem being with that post is that it does not pass any credentials. And again, the problem is not with the script, it works just fine but asks you for credentials each time. So I checked the links, and they are things I've already tried like "Integrated Security=SSPI", and using the uid= and pwd= commands. Nothing seems to want to pass credentials to this.
0
 
LVL 11

Expert Comment

by:Joe Klimis
ID: 37724968
which version of access are you using ?

Are you using user level security or DB password ?
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 22

Accepted Solution

by:
Nico Bontenbal earned 2000 total points
ID: 37725055
You need to store the credentials with the linked table in Access itself. See step 6 in the section "From SQL or another ODBC data source" of this page: http://office.microsoft.com/en-us/access-help/import-or-link-data-and-objects-HP005187610.aspx
0
 

Author Closing Comment

by:Alex_MPM
ID: 37729393
That sucks, because it is definitely not a secure way of accessing the data. But it does do the job. In this case the data isn't crucial anyways, but I would not recommend doing this for any kind of accounting DB or anything else with sensitive data.
0
 
LVL 22

Expert Comment

by:Nico Bontenbal
ID: 37729419
Having the pwd in a script is not secure either. Just make sure the database is in a secure location. If you schedule it at night I assume you'll use a server for that. Just put the file on a local drive on the server, not on a network share.
0
 

Author Comment

by:Alex_MPM
ID: 37729426
Good call. Thanks for your feedback.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question