Why does sqlcmd give a connection timeout but not SSMS - sql-server-2012

On my dev workstation, I'm connecting to a SQL Server 2012 database with SSMS, using the server name server,port -and it works perfectly.
However, on the same dev workstation, when I'm trying to connect to the same SQL Server, I get a connection timeout when using sqlcmd. The command line would be
sqlcmd -S server,port -E
Any idea why it works with SSMS but not with sqlcmd?

Related

sqlcmd on Windows/SQL Server 2016: Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'

We recently migrated to Windows 10 in a Windows 2016/SQL Server 2016 environment. The linked servers were supposedly set up the same as on the old network, but the following sqlcmd no longer works:
sqlcmd -S DBServer1 -q"Insert into DBServer2.Customers.dbo.Table2 (Field2) Select Field1 From Vendors.dbo.Table1"
Fails with:
Msg 18456, Level 14, State1, Server Database1, Line 1 Login failed for
user 'NT AUTHORITY\ANONYMOUS LOGON'
Servers and clients are in the same domain. If the code is run from a (non-database) server, it works normally.
Also, if I open up SSMS on a Windows 10 client machine and run the query, the above sqlcmd will afterward execute normally in a command pane, until the machine is rebooted or some amount of time has passed.
Setting up SA logins on the SQL Servers isn't an option. What needs to be configured so that sqlcmd hitting a linked server will work using Windows authentication in the domain?
For SQLCMD you'd want to use either the -E for windows authentication or -UYourLogin -PYourPassword

How to find SQL Server name in logging in to SQL Server Management Studio

How can I create a server name for database engine in logging in to SQL Server Management Studio?
Or how can I find my default server name? I have been using running SQLCMD -L this code in my command prompt but it turns me nothing it just says Servers:
You can try using Localhost or . to connect to your local instance.
Also, to reattach your database (from the mdf file), you can use the Attach Database command that is showed in the following image.
Hope this helps

Cannot connect to SQL Alias through PowerShell

I have a development VM setup as a domain controller with SQL Server 2012 installed. I am trying to connect directly on the server, but am unable to connect to my SQL Alias via PowerShell using the following commands:
$sqlServer = "sp2013sql"
$objSQLConnection = New-Object System.Data.SqlClient.SqlConnection
$objSQLCommand = New-Object System.Data.SqlClient.SqlCommand
$objSQLConnection.ConnectionString = "Server=$sqlServer;Integrated Security=SSPI;"
$objSQLConnection.Open()
I can directly through SQL Server Management Studio using the sp2013sql SQL Alias and via the name of the server.
This is what I have checked so far:
SQL Server is running
SQL Server Browser is running
SQL Server Agent is running
Firewall is turned off for all three profiles (doamin, private, and public)
Named Pipes and TCP/IP are enabled in SQL Server Network Configuration within the SQL Server Configuration Manager
TCP/IP is set to 1433
I can connect to the Alias via SQL Management Studio on the server
I can ping the name of the alias
I have a DNS A Record for the SQL Alias
I created an entry in the HOSTS file (Just in case I screwed up the DNS A Record)
SQL Browser is running
The Domain account for the SQL Browser service is a SYSADMIN in SQL Server
Running SQLCMD -L in CMD returns the name of my alias (and server)
Remote connections are enabled in SQL Server Management Studio
This is driving me crazy. What am I missing?
I eventually rebuilt from scratch. I think my problem was that I changed the SQL Browser Service Account but I cannot be sure.

Schedule task in sql express edition using batch file

Requirements - Schedule task in SQL Express Edition.
But SQL server Agent functionality is not available in express edition.
Possible Solution- Schedule batch file execution to execute sql script. Tried
Batch File-cmd /k sqlcmd -i backup.sql
Sql Script-backup database DB_user1212 to disk = 'E:\backups\MyBackup.bak'. But error occurred while executing sql script A network related or instance specific error occurred while establishing a connection to SQL Server
Possible Reason- Something like connection string missing. Help me how to solve this, i am using windows authentication for connection.
All you need to do is add the additional parameters to your call to sqlcmd.
sqlcmd -S yoursqlserver -E -i C:\pathto\backup.sql

How to schedule a script in SQL Server Express ( without SQL Server Agent )?

Ok so I asked a question yesterday about doing a timed procedure. I got some responses about using SQL Server Agent but i found out that I am using Sql server 2008 express RC and its not available.
Here is my first question and I want to know if there is another tool I can use to do a timed procedure with sql server ....thanks again
You can use dialog timers to start activated procedures. This functionality is available on the Express edition. The advantage over an external service, like Windows Scheduler, is that the solution is self contained inside the database. For example you can move the database to a different computer and the timed procedure will still run, on the new computer, once the database is started. An external service requires you to reconfigure the scheduler agent on the new computer.
You can use scheduled task (control panel-administrative tools) and start a .cmd/.bat file where you use sqlcmd to execute SP's or run scripts.
sqlcmd is a command line tool. sqlcmd /? will show you what you can do with it.
Here is how you can use sqlcmd to execute a SP called StoredProcName in database YourDatabase on server instance ComputerName\sqlexpress.
sqlcmd -S ComputerName\sqlexpress -E -d YourDatabase -Q "exec StoredProcName"
Read more about Using the sqlcmd Utility here http://msdn.microsoft.com/en-us/library/ms180944.aspx
Read about the Task Scheduler here http://msdn.microsoft.com/en-us/library/aa383614%28v=vs.85%29.aspx.