Using PowerShell to execute SQL commands in an Access environment

Source: Internet
Author: User

To use the data to connect to the database first, there are several ways to connect to access, I now use OLE DB connection mode. It is divided into no password and password.

No password connection text: Provider=microsoft.ace.oledb.12.0;data source=myaccessfile.accdb; Persist Security Info=false;
Have password connection text: Provider=microsoft.ace.oledb.12.0;data source=myaccessfile.accdb; Jet oledb:database Password=mydbpassword;

PowerShell new connection to use the cmdlet command, the New-object command:
$conn =new-object-typename system.data.oledb.oledbconnection $connstring
The above statement creates a new instance of the connection object first, and the variables for PowerShell are identified by $. Using the New-object command to create a new. NET object, System.Data.OleDb.OleDbConnection is the complete. NET object name, $connstring that is the beginning of the connection text, as in. NET object constructor, in order to instantiate the new object.
Then we create the command object, $cmd =new-object-typename system.data.oledb.oledbconnection $query, $conn
$query is the SQL command text, you must first open the connection $conn if you want the connection to take effect. Open ()
The Execute SQL command uses the $cmd.executenooquery () method, which returns the number of rows affected if the command executes successfully.
Do not forget to close the connection after the last operation
$conn. Close ()

The above is a recent contact with the use of PowerShell a little income, I am not a computer professional background, but work often with data, learn several ways to obtain data, recorded in this, in case of later check.

Using PowerShell to execute SQL commands in an Access environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.