dbTalk Databases Forums  

Cannot connect to database using osql with sa user

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss Cannot connect to database using osql with sa user in the microsoft.public.sqlserver.tools forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rob Hill
 
Posts: n/a

Default Cannot connect to database using osql with sa user - 07-13-2008 , 12:41 PM






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,

Rob



Reply With Quote
  #2  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM






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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #3  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #4  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #5  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #6  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #7  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #8  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #9  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
  #10  
Old   
TheSQLGuru
 
Posts: n/a

Default Re: Cannot connect to database using osql with sa user - 07-13-2008 , 04:55 PM



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" <robh71 (AT) nospam (DOT) nospam> wrote

Quote:
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,

Rob





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.