Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Doing a remote SQL query

Reply
 
Old 03-16-2007   #1 (permalink)
Marco Shaw


 
 

Doing a remote SQL query

What might be the best/most efficient way to have a SQL query run on a
remote machine? ADO.NET? ODBC? Other?

The remote machine will be running MSDE or possibly MS-SQL. Dunno if
there's a stored procedure I could use, but let's assume not.

Might the answer depend on the SQL query?

Marco



My System SpecsSystem Spec
Old 03-17-2007   #2 (permalink)
Joris van Lier


 
 

Re: Doing a remote SQL query

Marco Shaw wrote:
> What might be the best/most efficient way to have a SQL query run on a
> remote machine? ADO.NET? ODBC? Other?
>
> The remote machine will be running MSDE or possibly MS-SQL. Dunno if
> there's a stored procedure I could use, but let's assume not.
>
> Might the answer depend on the SQL query?
>
> Marco


Hi Marco,
since powershell is heavily .NET oriented i'd suggest you go with ADO.NET as you can allso apply your knowledge of ADO.NET to .NET programming in general.
Powershell allso knows out of the box how to format ADO.NET objects in the pipeline, for instance a cmdlet returning a DataTable to the pipeline will result in a format-table output with the columns in the datatable, on the contrary returning an ADODB Recordset results in a format-list of the properties of the Recordset object and you'll have to create custom formatting to display that nicely.

Ado.NET comes two general purpose data providers: ODBC or OLEDB, which one to use depends on your database driver, MSSQL and mysql can be accessed via ODBC, but in the case of MS SQL Server there are specialized classes in the System.Data.SqlClient namespace, and for Oracle there's the System.Data.OracleClient .

The type of query will allow you to optimize the flow of data using Execute... method of an Ado.NET DbCommand if you need the results in a certain format (1e one valye, one row or a DataReader) or no results at all , i'll paste some info from .NET Framework 2.0 Documentation:

ExecuteScalar Executes the query and returns the first column of the first row in the result set returned by the query. All other columns and rows are ignored.

You can use ExecuteNonQuery to perform catalog operations (for example, querying the structure of a database or creating database objects such as tables), or to change the data in a database by executing UPDATE, INSERT, or DELETE statements.
Although ExecuteNonQuery does not return any rows, any output parameters or return values mapped to parameters are populated with data.
For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1.

hth

Joris
My System SpecsSystem Spec
Old 03-17-2007   #3 (permalink)
RichS


 
 

RE: Doing a remote SQL query

Definitely ADO.NET if at all possible. I'll send you an example
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Marco Shaw" wrote:

> What might be the best/most efficient way to have a SQL query run on a
> remote machine? ADO.NET? ODBC? Other?
>
> The remote machine will be running MSDE or possibly MS-SQL. Dunno if
> there's a stored procedure I could use, but let's assume not.
>
> Might the answer depend on the SQL query?
>
> Marco
>
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Remote Assistance + video (or animated gifs) on the remote screen Vista General
System.Management.ManagementException 'generic failure' during remote WMI query .NET General
How to view remote certificates installed on remote machine? PowerShell
checked for logged on user on remote machine + remote reboot PowerShell
Remote connection query Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46