How to catch Sqlcmd errors without showing the error message - shell

I am trying to find out with SQLEXPRESS is installed on a server by running the following
sqlcmd -S LT1183 -U uname -P pass123 -Q "SELECT ##servername"
If it is installed it gives out the server name but if its not, it throws the below error.
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : TCP Provider: Error code 0x2AF9.
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : 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.
I am looking for a way to suppress this error and instead show a custom error message. Is that possible?
Thanks in advance.

This may not be possible with sqlcmd, since the error stems from connecting the the server, which upon error immediately terminates the sqlcmd.
if you can use powershell, you may find some luck using invoke-sqlcmd.
Powershell Try Catch invoke-sqlcmd

Related

Oracle sql developer connection - Status : Failure -Test failed: IO Error: The Network Adapter could not establish the connection

I download oracle sql developer "Windows 64-bit with JDK 8 included" from oracle website /download section. I unzipped it and tried to make a connection. I tried couple of options but I am getting "Status : Failure -Test failed: IO Error: The Network Adapter could not establish the connection" error.
Can any one help me with this. Thank you
Do you have a database?
I downloaded SQL Developer, now what?
SQL Developer is just a client, you need a database to connect to.

ORA-12170: TNS:Connect timeout occurred on CentOS 7

I am configuring a server in CentOS 7 to connect to an Oracle database within the same network. IP ORACLE = 192.167.10.100 IP SERVER = 192.167.15.123
I have installed the Instant Client Package: Basic, SDK and SQL * Plus. Download link
Then set the environment variables:
ORACLE_HOME=/usr/lib/oracle/12.2/client64
PATH=$PATH:$ORACLE_HOME/bin
LD_LIBRARY_PATH=$ORACLE_HOME/lib
TNS_ADMIN=$ORACLE_HOME/network/admin
When entering with the SQL * Plus through the implicit connection string: With the format.
sqlplus username/password#host:port/sid
sqlplus testuser/orcltiger#192.167.10.100:1521/testdb
I get the error: ORA-12170: TNS: the connection timeout occurred
I have been able to connect with the same credentials from a Windows PC with Oracle SQL Developer but from CentOS I get an error:
Someone to help me find the solution, please.

ORA-12560: TNS: protocol adapter error

I have installed oracle client winx64_12102_client and configured tnsnames.ora . when I try to login with connect with sqlplus /nolog and then connect enter username and password.
It gives me error
ORA-12560: TNS: protocol adapter error.
I have been through many forums and have set ORACLE_HOME, PATH and TNS_ADMIN, but I am still getting the error.
In the Oracle net configuration assistant when i test if I am able to connect to database. the test succeeds, but in sqlplus I get this error
For client
I used username as username#servicename and password and then it worked.

Visual Studio 2013 Test Explorer - Discover Tests Failed to initialize data storage for staging test results

I constantly get the following error when opening the test explorer in VS2013:
Failed to initialize data storage for staging test results as it threw the following exception:
'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Error occurred during LocalDB instance startup: SQL Server process failed to start.
In the EventViewer I see the following entry:
Source: SQLLocalDB 12.0
Message: Windows API call WaitForMultipleObjects returned error code: 575. Windows system error message is: {Application Error}
The application was unable to start correctly (0x%lx). Click OK to close the application.
Reported at line: 3728.
Does anybody have the same problem and know how to get rid of this error?
Best regards
Yannik
Finally, I found a solution that worked in my case.
Delete the instance folder of local db called "v11.0" (C:\Users\theUser\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0)
Start cmd window and execute the following command: sqllocaldb create "v11.0"
After this, the problems within the test explorer were solved.
Yannik had the solution....local DB (v17) is now called MSSQLLocalDB.
Delete "MSSQLLocalDB"
(C:\Users\theUser\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\MSSQLLocalDB)
Create a new one.
sqllocaldb create "MSSQLLocalDB"

Debugging In SQLDeveloper over SSH Tunnel

I am using SQL Developer over an SSH tunnel to my database server without any problems. However, it fails when I try to use the debugger. The debugging window shows:
Executing PL/SQL: CALL DBMS_DEBUG_JDWP.CONNECT_TCP( '10.72.227.252', '52413' )
But then I get the errors:
ORA-30683: failure establishing connection to debugger
ORA-12535: TNS:operation timed out
ORA-06512: at "SYS.DBMS_DEBUG_JDWP", line 68
ORA-06512: at line 1
Is there a special listener that has to be running on the database server in order to debug over the network? It looks like the CONNECT_TCP call is trying to connect to a different port (52413 in the above example) every time I run it. How do I debug in SQL Developer over an SSH tunnel?
The oerr command shows this for the ORA-30683 error:
ORA-30683: failure establishing connection to debugger
Cause: An error was indicated when trying to establish a connection to a debugger. Usually a TNS error will display along with this message to further explain the problem, although this TNS error will likely be hidden if you choose to trap the error. In your case you also get the ORA-12535 operation timed out error.
Action: Correct the indicated parameter value and try again.
For details check here
Run
Solution
SQL> grant debug connect session, debug any procedure to
Well experienced same problem, try these solutions:
1- Grant debug connect session to urUser;
Grant Debug any procedure to urUser;
2 - Tools -> preferences -> debugger and mark ask host for debugging...
3- when you compile be sure to give the ip adress with which ur machine on where sql developper is running, if it still doesnt work, try to turn off the firewall and retest it.
Temporary solution: switch debugger from jdwp to old version.
Add at the end of the ide.properties:
DatabaseDebuggerDisableJDWP=true
This file location:
C:\Users\username\AppData\Roaming\SQL Developer\system${VERSION}\o.sqldeveloper.${SYSTEM_VERSION}

Resources