Connecting to SQL DB

Hello,


I am writing a script in WQL (WMI for SQL) and I need to first connect to a machine running SQL and then specify the database to use. Of course, I can use the "USE" command to specify database to use but I am having an issue knowing which statement(s) I need to sue to establish the actual connection to the SQL DB instance name. Since the WQL query will be run locally on the machine the same SQL box, I am not sure if I need to specify credentials in the connection attempt but if that option is available, I would be interested in this as well.
Any help is appreciated.

Thank You
Charlie_MelegaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TempDBACommented:
Yes you need to. As it is an application, it has to pass the credentials.
0
Daniel_PLDB Expert/ArchitectCommented:
Hi,

If windows account under which context application will be running has apropriate SQL Server access you don't need to provide credentials.

Microsoft states as following:

To access the WMI Provider for Server Events, the client on which a WMI management application originates must correspond to Windows authenticated login or group in the instance of SQL Server specified in the application's connection string of the application.

Working with the WMI Provider for Server Events
Understanding the WMI Provider for Server Events

Some samples:
PowerShell and SQL Server Events – Monitoring SP Recompilations
Event Notifications using Powershell, WMI, WQL and SQL Server 2008
SQL Server Administration with Powershell - google books online sample chapters

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Eugene ZCommented:
There are many SQL (some for sql server,  some for windows)
WQL is sql to query Windows "database" not sql server

http://msdn.microsoft.com/en-us/library/windows/desktop/aa392902(v=vs.85).aspx

--

Windows Management Instrumentation Query Language (WQL) is Microsoft's implementation of the CIM Query Language (CQL),
http://en.wikipedia.org/wiki/WQL

--
if you are really wish to query sql server check above posts links

--
if you are local windows admin - -with WQL you can check system level of sql server : if service is running , etc
you can try  the below code -- no need for your login info:


strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" _
    & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
    "SELECT * FROM Win32_NTLogEvent " _
    & "WHERE Logfile = 'Application",,48)

0
Charlie_MelegaAuthor Commented:
Thanks Guys
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.