Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Osql utility

Author  Topic 

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-07 : 13:37:48
can anyone leave a feedback if this is a correct statement!

osql -S\\CCASDFGDF -dmydb -Usa -P -q"select @@version"


When I ping on the machine it is pingable. however, when i run the above i get an error:
[DBNETLIB]SQL Server does not exist or access denied.
[DBNETLIB]ConnectionOpen (Connect()).


--------------------------
Joins are what RDBMS's do for a living

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-07 : 13:41:38
-S CCASDFGDF

And if you have a named instance, you'll need to include that too: -S CCASDFGDF\InstanceName

Pinging isn't enough. What matters is if you can telnet to the port SQL is listening on.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-07 : 13:47:39
I dont have the IPaddresses, I do have only the host names, which I get from the host file.

I tried it without back slashes, the same error:
osql -S CCASDFGDF -dmydb -Usa -P -q"select @@version"


--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-07 : 13:49:37
You don't need the IP address, but you do need to find out the port since it's not working without the back slashes. Are you the DBA for this system?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-07 : 14:46:14
Noo...I'm a programmer just developing some SQL script that runs remotely from this machine...and I need to know which windows version this remote machine is running!

Any help will be appreciated.

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-07 : 15:28:17
You'll need to find out the port for the SQL Server you are trying to connect to. Contact the DBA to find out, and then we can help you get connected.

If you only need to find out the Windows version, then just ask the DBA.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-07 : 15:50:53
well, I can't contact each DBA because I have about 30 machines.
But I DO have access through remote Desktop to the whole system.
is there anyways how to find out which port by going in and looking for it?

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-07 : 15:53:03
Yes you can view in SQL Server Configuration Manager as well as in the SQL Server Error Log.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-07 : 16:08:46
[code]OK, sounds good. however,what Info I would extract from those utilities to be used to correct my command?

osql -S CCASDFGDF -dmydb -Usa -P -q"select @@version"
Again: my pupose is to automate a script that extract windows version of all machine existing in the host[/code]


--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-07 : 16:11:03
If you have the port number, you should be able to connect with this:

osql -S CCASDFGDF,PortNumberGoesHere -dmydb -Usa -P -q"select @@version"



Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-07 : 16:12:46
quote:
Originally posted by xhostx


Again: my pupose is to automate a script that extract windows version of all machine existing in the host





You'll need to enumerate the instances on a server. I believe you can that via tools and Powershell. It is not something you can do via osql. You need the list of instances to connect to for osql to work.


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-07 : 16:33:45
[code]I added the port which I got from Enterprise Manager

As follows:
>osql -S CCADFRAD,1433 -dmydb -Usa -P -q"select @@VERSION"
the same error:
[DBNETLIB]SQL Server does not exist or access denied.
[DBNETLIB]ConnectionOpen (Connect()).[/code]

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-07 : 16:58:03
You need to work with your network admin then.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-13 : 09:50:06
[code]Thanks, Solved. I didn't have to add the port#
>sqlcmd -S RemoteServer -dremotDB -USQLUSER -PSQLPASS -Q"select @@version"[/code]

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-13 : 12:33:38
You definitely don't need to add the port number. I was having you add it for troubleshooting purposes.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2012-09-13 : 12:51:17
Tara, I kind of realized that. It was just for the purpose of information.
Thanks for standing by anyways :).

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-09-13 : 12:56:11


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -