Friday, March 23, 2012

Error when Logging on - Error: 18456, Severity: 14, State: 16

Hi All,
I am getting the following error in the ERRORLOG File when I am
trying
to connect to SQL Server 2005 Express Edition from the command line.
2007-03-23 07:30:05.54 Logon Error: 18456, Severity: 14, State:
16.
2007-03-23 07:30:05.54 Logon Login failed for user 'sa'.
[CLIENT: xx.xx.xx.xx]
I have a fresh install of SQL Server on my local machine, which is
probably the source of my angst, but I am trying to create a database
from scratch through using a batch file that is run from the command
line, the batch file looks like this:
<snip>
SQLCMD -U %USR% -P %PWD% -S %SVR% -d %DBF% -i CreateDatabase.sql
<snip>
The values of %USR% and %PWD% are correct as I frequently log into
Management Studio with the details, %SVR% is "<ComputerName>
\SQLEXPRESS,1433" and %DBF% is <DatabaseName>. The contents of
CreateDatabase.sql when run in Management Studio successfully creates
the database that I require so I know the error doesn't lie there.
The command line error that is showing reads as the following:
Msg 4060, Level 11, State 1, Server <ComputerName>\SQLEXPRESS, Line 1
Cannot open database "<DatabaseName>" requested by the login. The
login failed.
Msg 18456, Level 14, State 1, Server <ComputerName>\SQLEXPRESS, Line
1
Login failed for user 'sa'.
I have a feeling that it is related to 'sa' not having the correct
permissions with regards to logging into or creating a database from
scratch, but I find it odd that I can login as 'sa' in Management
Studio and create the database from there, but when I try it from the
command-line (despite having TCP/IP enabled) it won't let me connect
to create a database.
Is there something I am missing here? I have been banging my head off
of walls for days over this and am unsure of the next steps to take.
If any of this screams "why the hell are you doing this?" then please
let me know as at the moment I am punching in the dark with this
problem, I have searched Usenet, Google Groups, the Web and although
I
have found potential solutions to this particular problem I am
having,
nothing I have done so far has actually managed to fix the issue.
Related articles I have followed are:
Login failed for user 'x'
http://msdn2.microsoft.com/en-us/library/ms366351.aspx
Change Server Authentication Mode
http://msdn2.microsoft.com/en-us/library/ms188670.aspx
Upgrading MSDE 2000 to SQL Server 2005 Express [Enabling network
protocols section]
http://www.microsoft.com/technet/pr...e2sqlexpress...
NOTE: I just listed these articles to show what path I am currently
looking at with regards to this problem, but again I stress I have
found nothing yet to get round this problem, and any further articles
or direction would be much appreciated.
Yours Distressingly
AlastairI'm still not clear on what database is used for -d
<DatabaseName> and this could be one of the problems. If you
are trying to log in using the database you are about to
create, then that's likely the issue as it doesn't exist
when logging in. Try specifying master for the initial login
database.
-Sue
On 23 Mar 2007 08:48:10 -0700, "Alastair"
<alastair_anderson@.hotmail.com> wrote:

>Hi All,
>I am getting the following error in the ERRORLOG File when I am
>trying
>to connect to SQL Server 2005 Express Edition from the command line.
>
>2007-03-23 07:30:05.54 Logon Error: 18456, Severity: 14, State:
>16.
>2007-03-23 07:30:05.54 Logon Login failed for user 'sa'.
>[CLIENT: xx.xx.xx.xx]
>
>I have a fresh install of SQL Server on my local machine, which is
>probably the source of my angst, but I am trying to create a database
>from scratch through using a batch file that is run from the command
>line, the batch file looks like this:
>
><snip>
>SQLCMD -U %USR% -P %PWD% -S %SVR% -d %DBF% -i CreateDatabase.sql
><snip>
>
>The values of %USR% and %PWD% are correct as I frequently log into
>Management Studio with the details, %SVR% is "<ComputerName>
>\SQLEXPRESS,1433" and %DBF% is <DatabaseName>. The contents of
>CreateDatabase.sql when run in Management Studio successfully creates
>the database that I require so I know the error doesn't lie there.
>
>The command line error that is showing reads as the following:
>
>Msg 4060, Level 11, State 1, Server <ComputerName>\SQLEXPRESS, Line 1
>Cannot open database "<DatabaseName>" requested by the login. The
>login failed.
>Msg 18456, Level 14, State 1, Server <ComputerName>\SQLEXPRESS, Line
>1
>Login failed for user 'sa'.
>
>I have a feeling that it is related to 'sa' not having the correct
>permissions with regards to logging into or creating a database from
>scratch, but I find it odd that I can login as 'sa' in Management
>Studio and create the database from there, but when I try it from the
>command-line (despite having TCP/IP enabled) it won't let me connect
>to create a database.
>
>Is there something I am missing here? I have been banging my head off
>of walls for days over this and am unsure of the next steps to take.
>
>If any of this screams "why the hell are you doing this?" then please
>let me know as at the moment I am punching in the dark with this
>problem, I have searched Usenet, Google Groups, the Web and although
>I
>have found potential solutions to this particular problem I am
>having,
>nothing I have done so far has actually managed to fix the issue.
>
>Related articles I have followed are:
>
>Login failed for user 'x'
>http://msdn2.microsoft.com/en-us/library/ms366351.aspx
>
>Change Server Authentication Mode
>http://msdn2.microsoft.com/en-us/library/ms188670.aspx
>
>Upgrading MSDE 2000 to SQL Server 2005 Express [Enabling network
>protocols section]
>http://www.microsoft.com/technet/pr...e2sqlexpress...
>
>NOTE: I just listed these articles to show what path I am currently
>looking at with regards to this problem, but again I stress I have
>found nothing yet to get round this problem, and any further articles
>or direction would be much appreciated.
>
>Yours Distressingly
>
>Alastair|||On 25 Mar, 16:17, Sue Hoegemeier <S...@.nomail.please> wrote:
> I'm still not clear on what database is used for -d
> <DatabaseName> and this could be one of the problems. If you
> are trying to log in using the database you are about to
> create, then that's likely the issue as it doesn't exist
> when logging in. Try specifying master for the initial login
> database.
> -Sue
> On 23 Mar 2007 08:48:10 -0700, "Alastair"
>
> <alastair_ander...@.hotmail.com> wrote:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
You managed to hit the nail on the head.
Running my current script when the new database already exists it
works fine, however for a fresh install of SQL Server, when it doesn't
currently exist then it doesn't work.
Thanks for your help
Alastair

No comments:

Post a Comment