Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

sqlcmd not showing user databases

Posted on 2010-09-19
7
Medium Priority
?
765 Views
Last Modified: 2012-05-10
I'm trying to connect to my database via sqlcmd to run a query (sql file).
sqlcmd -s ServerName -E

Then I do a "USE MyDatabase -> GO"

Then I get this message

"Could not locate the entry in the sysdatabase for database 'MyDatabase'. No entry found with that name."

I can do a select * from sys.databases inside sqlcmd and I get the 4 system databases - but not any user ones. I can access everything just fine via management studio to the databases using the same windows auth - just not via sqlcmd. This acting the same for me for sql server 2005/2008/2008r2. All are patched and up to date.

Any ideas on how I can fix this?

Thanks!
0
Comment
Question by:rmm2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33713385
Are you running multiple SQL Server instances?
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33713395
Run this in SQLCMD and then in SSMS

select @@SERVERNAME
0
 
LVL 7

Author Comment

by:rmm2001
ID: 33713401
Yes to the instances. I have 3 of them up. When I do @@SERVERNAME in ssms it bring back the name of that instance
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33713427
sqlcmd can also connect to instances:

sqlcmd -S ServerName\Instance -E

(use upser case -S)
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 2000 total points
ID: 33713430
Lower case -s is the column separator
Upper case -S is the server/instance
usage: Sqlcmd            [-U login id]          [-P password]
  [-S server]            [-H hostname]          [-E trusted connection]
  [-d use database name] [-l login timeout]     [-t query timeout]
  [-h headers]           [-s colseparator]      [-w screen width]
  [-a packetsize]        [-e echo input]        [-I Enable Quoted Identifiers]
  [-c cmdend]            [-L[c] list servers[clean output]]
  [-q "cmdline query"]   [-Q "cmdline query" and exit]
  [-m errorlevel]        [-V severitylevel]     [-W remove trailing spaces]
  [-u unicode output]    [-r[0|1] msgs to stderr]
  [-i inputfile]         [-o outputfile]        [-z new password]
  [-f <codepage> | i:<codepage>[,o:<codepage>]] [-Z new password and exit]
  [-k[1|2] remove[replace] control characters]
  [-y variable length type display width]
  [-Y fixed length type display width]
  [-p[1] print statistics[colon format]]
  [-R use client regional setting]
  [-b On error batch abort]
  [-v var = "value"...]  [-A dedicated admin connection]
  [-X[1] disable commands, startup script, enviroment variables [and exit]]
  [-x disable variable substitution]
  [-? show syntax summary]

Open in new window

0
 
LVL 7

Author Comment

by:rmm2001
ID: 33713436
The capital 'S' worked! And my file ran! Thank you so much!
0
 
LVL 7

Author Closing Comment

by:rmm2001
ID: 33713440
it works!
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question