Welcome to MSDN Blogs Sign in | Join | Help

Demo SQL Provider Code

Hi,

Attached is the code we used today in the Web cast for the SQL demo provider. Please note this is not a SQL management provider. It simply allows you to query data from a SQL server directly from the cmd line.

Install the Snapin: 

PS>$env:Windir\Microsoft.NET\Framework\v2.0\.50727\InstallUtil.exe SQLProvider.dll

Add the snapin to your session:

PS>Add-PsSnapin SqlPrototypeProvider

You can use it as follows:

PS>cd SQL:

SQL:>cd MySQLServer

SQL:>dir

master
tempdb
model
msdb
pubs
Northwind

SQL:>cd Northwind

SQL:>dir

name
----
Categories
CustomerCustomerDemo
CustomerDemographics
Customers
dtproperties
Employees
EmployeeTerritories
Order Details
Orders
Products
Region
Shippers
Suppliers
Territories

SQL:>cd Employees

SQL:>Dir -filter {where EmployeeId=8}

EmployeeID      : 8
LastName        : Callahan
FirstName       : Laura
Title           : Inside Sales Coordinator
TitleOfCourtesy : Ms.
BirthDate       : 1/9/1958 12:00:00 AM
HireDate        : 3/5/1994 12:00:00 AM
Address         : 4726 - 11th Ave. N.E.
City            : Seattle
Region          : WA
PostalCode      : 98105
Country         : USA
HomePhone       : (206) 555-1189
Extension       : 2344
Photo           : {21, 28, 47, 0...}
Notes           : Laura received a BA in psychology from the University of Washington.  She has also completed a course
                   in business French.  She reads and writes French.
ReportsTo       : 2
PhotoPath       : http://accweb/emmployees/davolio.bmp

 Wassim [MSFT]

 

 

Published Thursday, June 21, 2007 3:19 AM by PowerShellTeam

Attachment(s): SQLProvider.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# PowerShellからデータベースの中身を見る

Demo SQL Provider Code PowerShellを利用して、SQL Serverのデータベースの中身をまるでフォルダやファイルをたどるようにして見ることのできるサンプルプロバイダのコードが提供されています。こんなことできるんですねぇ。。。...

Thursday, June 21, 2007 12:31 AM by どっとねっとふぁんBlog

# re: Demo SQL Provider Code

Hello folks!

I just downloaded the provider and installed it. No errors.

Then I tried to add-pssnapin and powershell came back telling me, there are no snap ins in version 1.0.

What's going wrong?

Cheers!

quax

Thursday, June 21, 2007 3:07 AM by quax

# re: Demo SQL Provider Code

Great, but ...

1) Guess, there's a surplus backslash in your cmd line? IMHO it should read: ...\v2.0.50727\...

2) How do I connect using SQL Authentication?

JensG

Thursday, June 21, 2007 3:41 AM by JensG

# re: Demo SQL Provider Code

There is a bug in the first line of script:

It should be:

PS>. $env:Windir\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe SQLProvider.dll

Note the "." before the path and the removal of the directory in the Framework version directory.

Cool entry though.

John

Thursday, June 21, 2007 6:54 AM by John

# re: Demo SQL Provider Code

What webcast was this?  I try to join them all...

Thursday, June 21, 2007 7:37 AM by Marco Shaw

# Windows PowerShell用Demo SQL Provider公開(Web castでのDemo用)

Windows PowerShell用Demo SQL Provider公開(Web castでのDemo用)

Thursday, June 21, 2007 7:52 AM by 米田 Blog ( SQL Server MEMO )

# re: Demo SQL Provider Code

quax, if you are using x64 you have to use the correct framework.

Windows\Microsoft.NET\Framework64\v2.0.50727\InstallUtil.exe

Thursday, June 21, 2007 11:43 AM by BSonPosh

# re: Demo SQL Provider Code

Marco,

Event Name: TechNet Webcast: Windows PowerShell in Windows Server 2008 (Level 200)

Start Date: 6/20/2007

Start Time: 1:00 PM (GMT-08:00) Pacific Time (US & Canada)

Please click on the following link for more information regarding this Event https://msevents.microsoft.com/cui/r.aspx?r=1291248013&c=en-US&t=4.

Thursday, June 21, 2007 11:44 AM by Aleksandar

# re: Demo SQL Provider Code

I have SQL Express.  SQL server management studio express says my server name is "NB517949\SQLEXPRESS".  I can't seem to figure out the proper combination to cd into...  Any ideas?  

(I'm able to use that server name using invoke-sql from PowerGadgets to run stuff against the DB.)

Thursday, June 21, 2007 9:07 PM by Marco Shaw

# [powershell][sql]PowerShellのSQL用プロバイダ

Sorry,this entry is written only Japanese. http://blogs.msdn.com/powershell/archive/2007/06/21/demo-sql-provider-code.aspx インストール。このページには「¥v2.0¥.50727¥」て書いてあるけど「¥v2.0.50727¥」の間違いだよね。 エラった。。$env:Windor がよくないの

Thursday, June 21, 2007 11:56 PM by 学び、そして考える

# re: Demo SQL Provider Code

Can the prototype provider be made to connect to a named instance?

Thanks,

Chris Leonard

Friday, June 22, 2007 11:22 AM by chrisleonard

# re: Demo SQL Provider Code

Haven't tried it yet, but having a SQL provider ROCKS!  I SO need this.

Friday, June 22, 2007 11:48 AM by Mike Schinkel

# SQL Server Powershell Provider

Dopo la SQL Conference ho iniziato a scrivere un provider SQL Server per PowerShell. Per chi non sapesse

Saturday, June 23, 2007 11:53 AM by Impedance Mismatch

# re: Demo SQL Provider Code

The SQL provider demo code is very fragile specifically when it comes to parsing the path. the code does not support a named instance as NB517949\SQLEXPRESS. The code takes "NB517949" as Server name and SQLEXPRESS as the data base name.

The authentication is done on the SQL server. I did not add any credential parameter.

The installation syntax is wrong in the blog it should read $env:Windir\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe SQLProvider.dll

Also on 64 bit machines you need to invoke the correct version of InstallUtil.exe

Sunday, June 24, 2007 4:09 PM by Wassim [MSFT]

# re: Demo SQL Provider Code

Just curious ... is it possible to access  Views this way?  Because I use views more than tables.

Tuesday, June 26, 2007 11:28 AM by Kumar

# re: Demo SQL Provider Code

Hi Wassim,

Cool code. I was wondering, is there anything similar for browsing an object graph/hierarchy, I mean generically? Say I have a Customer object that has an Orders property. Is there a PowerShell provider that allow me to do, for example:

cd MyModel:

cd Customers

cd "John Doe"

cd Orders

dir *.Paid.*

? I thought this would be generic enough to be available right off the box, but I can't find a way to do it? Should I write my own code for this?

Thanks anyway :-)

Wednesday, June 27, 2007 4:35 PM by Simon Mourier

# re: Demo SQL Provider Code

"The authentication is done on the SQL server. I did not add any credential parameter."

how could I add a credential parameter?

Thanks

Jason S

Wednesday, August 01, 2007 11:54 AM by Jason S

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker