5

I am trying to use the command below to access my database within Azure

sqlcmd -s tcp:DBNAME HERE.database.windows.net -U USERNAME -P PASSWORD

I get the error

Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2]. . Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout expired. Sqlcmd: Error: Microsoft ODBC Driver 13 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..

Has anyone ever had this? I have downloaded the latest version of sqlcmd

I need to get a lot of data into my Azure database, but I am running out of options as the Import Data option in management studio cant cope. This was the first method I tried. After processing 70000 of 250000 rows it just goes to stopped with no error message, thats what then led me to try with BCP SQLCMD

Paul

Paul
  • 2,773
  • 7
  • 41
  • 96
  • Sorry I mean that I first tried to use the Import/Export data option to get data into my database thats the bit that didnt process. Management Studio can connect to my Azure database, so I know this is not a firewalll issue – Paul Nov 20 '17 at 19:46
  • yep just done that – Paul Nov 20 '17 at 19:49
  • Is it Azure SQL, or is it SQL Server running in Azure? Have you tried to [use PowerShell to load data](https://www.mssqltips.com/sqlservertip/5064/bulk-insert-data-into-a-azure-sql-database-with-powershell/) into it? – Mike Sherrill 'Cat Recall' Nov 20 '17 at 19:57
  • Its an Azure SQL database hosted inside an elastic pool – Paul Nov 20 '17 at 19:58
  • Will look at the power shell route – Paul Nov 20 '17 at 19:58

3 Answers3

6

Your command is incorrect. The 'S' should be capitalized and you should provide the server name, not the database name.

sqlcmd -S tcp:myServer.database.windows.net -d database -U username -P password

See the documentation page for the complete syntax of sqlcmd.

hokkaidi
  • 858
  • 6
  • 19
  • The tcp: prefix is not needed. I am wondering if the user is trying to run the sqlcmd from box that does not have the client libraries configured for TCP. That would result in the named pipes message. – CRAFTY DBA Nov 23 '17 at 03:19
1

Please make a ping to the name of your Azure SQL Database server as shown below:

C:\> ping myserver.database.windows.net

The ping command should fail but it should return the current IP of your SQL Azure Database server. If it fails to return that IP, then you cannot access to Azure server due to a DNS resolution problem.

If the ping command returned the IP address successful, then try to telnet your SQL Azure Database server as shown below.

C:\> telnet myserver.database.windows.net 1433

If the telnet command fails make sure your computer firewall or network hardware is allowing traffic to the IP returned on the previous step and make sure TCP port 1433 is open. If your are trying this from a corporate network, please contact your network administrator with this requirements.

Please note that you may need to enable the telnet command via Control Panel -> Program and Features -> Turn on/off features.

Alberto Morillo
  • 13,893
  • 2
  • 24
  • 30
0

I just want to point out that BCP and sqlcmd are two different tools.

BCP is the bulk copy command. The later is the command line tool for querying.

If you are getting a named pipes issue, you might not have the client and/or server libraries configured.

Please go to SQL Server Configuration manager to check the settings.

By default, Azure SQL database is using TCP and you do not need to tell it on the command line.

enter image description here

In the image above, I am connecting to a Azure SQL database using the correct switches from books on line. Querying the sys.tables catalog returns the information that I expect. Two tables with different names. One duplicated named table under different schemas.

The BCP command will work the same way. You might even want to try a format file.

I want to clarify your statement that importing is taking a long time. Please remember that Azure SQL database is platform as a service. The database tiers are set at predetermined DTU's. That means stuffing the server with a lot of data will result in a throttled server at MAX DTU's.

I would look at the portal and see if that is your situation.

In short, sqlcmd, bcp and the import/export wizard are perfect tools for data loads a lot larger than the numbers you are talking about. Just remember, syntax is key to any successful program!

CRAFTY DBA
  • 14,351
  • 4
  • 26
  • 30