Querying using osql

When executing any of the following commands:

osql -E -S ComputerName\InstanceName
osql -E -S ComputerName\InstanceName -i MyScript.sql -o MyOutput.rpt
osql -E -q "SELECT * FROM Northwind.dbo.Shippers"
osql -E -Q "SELECT * FROM Northwind.dbo.Shippers" -o MyOutput.rpt

I get the following error:

[SQL Server Native Client 10.0]SQL Server Network Interfaces: Connection
string is not valid [87].
[SQL Server Native Client 10.0]Login timeout expired
[SQL Server Native Client 10.0]A network-related or instance-specific error
has occurred while establishing a connection to SQL Server. Server is not
found or not accessible. Check if instance name is correct and if SQL Server
is configured to allow remote connections. For more information see SQL Server
Books Online.

However, I can, without having to log into the system and run queries SELECTfrom SSMS.

How to query SQL Server 2008 using osql?

+4
source share
2 answers

Do you have a registered account configured as a user on SQL Server?

I usually work with certain accounts and SQL Server logins instead of trusted logins, and then I simply specify the database coordinates on the command line with the -S, -D, -U and -P options:

osql -S %SERVERNAME% -U %USERNAME% -P %PASSWORD% -d %DBNAME% 

, - MyServer\SQL2008, - Foo, - Bar, - MyDB, :

osql -S MyServer\SQL2008 -U Foo -P Bar -d MyDB 

.

, SQL Server Management Studio , Widows ..

SSMS (, ), "" node . Windows , , .

.

+4

osql -E -S ComputerName\InstanceName -i MyScript.sql -o MyOutput.rpt

osql -E -S ComputerName\InstanceName -Q "SELECT * FROM Northwind.dbo.Shippers" -o MyOutput.rpt

, SQL Server TCP/IP

+2

Source: https://habr.com/ru/post/1598767/


All Articles