Up |
|
|
  |
Author: Rob HillRob Hill Date: Jul 13, 2008 10:41
I am writing a script to create a database for out application. Currently
the app attaches an mdf and ldf, but I don't like that solution.
I have a script that creates a database using sqlcmd.exe and I pass
variables to it using the -v option. It works fine.
When I attempt to run a second script via osql.exe it fails with the
following error:
C:\>osql.exe -S SERVER -U sa -P password -d NewDB -i 2_CreateDBObjects.sql
Cannot open database "NewDB" requested by the login. The login failed.
If I omit the input file, I get the same error:
C:\>osql.exe -S SERVER -U sa -P password -d NewDB -i 2_CreateDBObjects.sql
Cannot open database "NewDB" requested by the login. The login failed.
If I connect to a database other than the one I just created with the
script, it works:
C:\>osql.exe -S SERVER -U sa -P password -d ExistingDB
1> quit
C:\>
I'm at a loss here. I thought the sa account was supreme.
Any help would be greatly appreciated.
Thanks,
|
| Show full article (0.97Kb) |
|
| | 15 Comments |
|
  |
Author: TheSQLGuruTheSQLGuru Date: Jul 13, 2008 14:55
You cannot connect specifying a database to connect to which does not exist
(yet).
--
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net
"Rob Hill" wrote in message
news:eoIraDR5IHA.300@TK2MSFTNGP05.phx.gbl...
>I am writing a script to create a database for out application. Currently
>the app attaches an mdf and...
|
| Show full article (1.30Kb) |
|
| | no comments |
|
  |
Author: Rob HillRob Hill Date: Jul 13, 2008 18:42
The database does exist. Thanks for the drive by response.
Rob
"TheSQLGuru" earthlink.net> wrote in message
news:dI2dnQKbEPA65OfVnZ2dnUVZ_ovinZ2d@earthlink.com...
> You cannot connect specifying a database to connect to which does not
> exist (yet).
>
...
|
| Show full article (1.54Kb) |
| no comments |
|
  |
Author: Uri DimantUri Dimant Date: Jul 13, 2008 21:59
Rob
What does CreateDBObjects.sql script do? Can you connect to the NewDB via
SSMS?
"Rob Hill" wrote in message
news:%%23NMPnLV5IHA.1200@TK2MSFTNGP04.phx.gbl...
> The database does exist. Thanks for the drive by response.
>
> Rob
>
>
> "TheSQLGuru"
|
| Show full article (1.79Kb) |
| no comments |
|
  |
Author: Rob HillRob Hill Date: Jul 13, 2008 22:33
Uri,
The script creates tables and stored procedures. Even if I don't run the
script, I can't connect to the database with osql.exe.
I am able to access the database with the SQL Management Studio.
Rob
"Uri Dimant" iscar.co.il> wrote in message
news:%%232zW04W5IHA.3784@TK2MSFTNGP06.phx.gbl...
> Rob
> What does CreateDBObjects.sql script do? Can you connect to the NewDB via
> SSMS?
>
>
>
> "Rob...
|
| Show full article (2.18Kb) |
| no comments |
|
  |
Author: Uri DimantUri Dimant Date: Jul 13, 2008 22:57
Rob
Sorry I'm ask you about , but did you make sure that you provide correct
name of database?
"Rob Hill" wrote in message
news:OKuAdMX5IHA.1892@TK2MSFTNGP06.phx.gbl...
> Uri,
>
> The script creates tables and stored procedures. Even if I don't run the
> script, I can't...
|
| Show full article (2.48Kb) |
| no comments |
|
  |
Author: Erland SommarskogErland Sommarskog Date: Jul 14, 2008 01:37
Rob Hill (robh71@nospam.nospam) writes:
> The database does exist. Thanks for the drive by response.
The error message you indicates that the database is not accessible. This
could be because it does not exist, or beause it is in single-user mode.
Since we don't see your system and your actual command-line, we cannot help
you much more than this. But you could try:
OSQL -S SERVER -U sa -P pwd
Then at this prompt type USE followed by space. Then you copy and paste the
database name from the failed command line, press return and then go, and
see what error message you may get now.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
|
| |
| no comments |
|
  |
Author: Rob HillRob Hill Date: Jul 14, 2008 08:47
Yes I did.
Rob
"Uri Dimant" iscar.co.il> wrote in message
news:%%23vI%%23pZX5IHA.1176@TK2MSFTNGP02.phx.gbl...
> Rob
> Sorry I'm ask you about , but did you make sure that you provide correct
> name of database...
|
| Show full article (2.72Kb) |
| no comments |
|
  |
Author: Rob HillRob Hill Date: Jul 14, 2008 08:54
That's a good idea. I didn't think about that.
Here's the result.
C:\>osql.exe -S SERVER -U sa -P password
1> use NewDB
2>
The database exists, and I can enter the use command without error, but if I
specify the database on the command line
C:\>osql.exe -S SERVER -U sa -P password -d NewDB
Cannot open database "NewDB" requested by the login. The login failed.
Thanks,
Rob
"Erland Sommarskog" wrote in message
news:Xns9ADB6C0715EB4Yazorman@127.0.0.1...
> Rob Hill (robh71@nospam.nospam) writes:
>> The database does exist. Thanks for the drive by response...
|
| Show full article (1.41Kb) |
| no comments |
|
  |
|
|
  |
Author: Russell FieldsRussell Fields Date: Jul 14, 2008 09:06
Rob,
I sense your frustration, but I have a question. Did you do the following:
C:\>osql.exe -S SERVER -U sa -P password
1> use NewDB
2>
3> GO
If you did not do the GO, your "use NewDB" never executed. (Another
question, is your server using a case sensitive collation?)
RLF
"Rob Hill" wrote in message
news:eCybjnc5IHA.2260@TK2MSFTNGP03.phx.gbl...
> That's a good idea. I didn't think about that.
>
> Here's the result.
>
> C:\>osql.exe -S SERVER -U sa...
|
| Show full article (1.86Kb) |
| no comments |
|
|
|