Hey guys,
I am hung up one last aspect (not being a devel :>)...
The original scenario had sqlcmd invoked with the "-I" parameter for Quoted 
Identifiers.

I see this exists as a method for use here as well. The code I am using which 
is essentially what Steve outlined is partially:

$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection

How exactly do I set that method?

Thanks guys,
jlc

________________________________________
From: Steve Kradel [skra...@zetetic.net]
Sent: Monday, April 02, 2012 11:49 AM
To: NT System Admin Issues
Subject: Re: Powershell ODBC and SQL scripts

What are your "raw materials" -- will you have one file with a bunch
of T-SQL for MSSQL, and a separate file with a bunch of PL/SQL for
Oracle?  Or are you trying to implement some logic in the code itself,
that will "just work" on various database platforms?

If the latter, this is a rather difficult problem.  Project like
NHibernate and FluentMigrations exist in this space... it is some
effort to learn how to use them, and they don't do everything anyway
(*especially* in the area of DDL / sprocs / etc.).

If the former, there are plenty of C# and VB.NET examples out there;
the general pattern is below... You should be able to adapt this to
Powershell with the [new-object] mumbo jumbo... this stuff is in the
System.Data.Common namespace:

/* 'factory' is the invariant name of a DbProviderFactory known to the
.NET runtime, registered either in app.config or machine.config */
var factory = DbProviderFactories.GetFactory(factory);
var conn = factory.CreateConnection();

/* 'cstr' is a database-specific connection string; something like
'Data Source=.;Initial Catalog=foo' for MSSQL */
conn.ConnectionString = cstr;
conn.Open();

/* now do stuff */
var cmd = conn.CreateCommand();
cmd.CommandText = "select * from blar"; // or pull commands from a file

--Steve
~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to listmana...@lyris.sunbeltsoftware.com
with the body: unsubscribe ntsysadmin

Reply via email to