Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, March 28, 2012

Login failed for user 18456 when using asymmetric key for login

Hi,

I wanted to check the asymmetric key option in sql 2005. I copied the books online code for creating a asymmetric key and then used this key for creating a login. Now when I try to login without entering any password I am receiving 18456 error. I would like to know what I am missing here. If I use CREATE LOGIN from asymmetric key or certificate how do I login and with what credentials. Do I need to provide any password.

CREATE ASYMMETRIC KEY PacificSales09 WITH ALGORITHM = RSA_2048 ENCRYPTION BY PASSWORD = 'bmsA$dk7i82bv55foajsd9764'; GO

CREATE LOGIN asm FROM ASYMMETRIC KEY PacificSales09;

Regards,

Ravi

After Creating a login you will have to give explicit permissions of connectivity and other things to the login, was that done?|||

Hi,

Thanks for the response. Yes I did create a user for the login and put in the reader/writer role. So that was not the issue here.

Even if I do not grant these permissions by default it should still have permissions that a Guest login would have so I would still be able to get connected to the server. Same stuff works for other logins I have the problem only when I create a login from certificate and asymmetric key sources.

I think I do not have to supply a password for my login when I create it using certificate and asymmetric key sources.

I still do not understand how do I use a login created from these sources and what difference does it make from a normal login.

Regards,

Ravi

|||

Logins mapped to certificates or asymmetric keys cannot be used for authentication with SQL Server - you cannot login with them. These logins are used to assign server-level permissions to the certificates/asymmetric keys that are mapped to them, which is useful for signing; that is their sole purpose. For an example of use, see the following example:

http://blogs.msdn.com/lcris/archive/2005/06/15/429631.aspx

Thanks
Laurentiu

|||

Thanks a lot. It helped me in understanding their usage.

Regards,

Ravi

Login failed for user 18456 when using asymmetric key for login

Hi,

I wanted to check the asymmetric key option in sql 2005. I copied the books online code for creating a asymmetric key and then used this key for creating a login. Now when I try to login without entering any password I am receiving 18456 error. I would like to know what I am missing here. If I use CREATE LOGIN from asymmetric key or certificate how do I login and with what credentials. Do I need to provide any password.

CREATE ASYMMETRIC KEY PacificSales09 WITH ALGORITHM = RSA_2048 ENCRYPTION BY PASSWORD = 'bmsA$dk7i82bv55foajsd9764'; GO

CREATE LOGIN asm FROM ASYMMETRIC KEY PacificSales09;

Regards,

Ravi

After Creating a login you will have to give explicit permissions of connectivity and other things to the login, was that done?|||

Hi,

Thanks for the response. Yes I did create a user for the login and put in the reader/writer role. So that was not the issue here.

Even if I do not grant these permissions by default it should still have permissions that a Guest login would have so I would still be able to get connected to the server. Same stuff works for other logins I have the problem only when I create a login from certificate and asymmetric key sources.

I think I do not have to supply a password for my login when I create it using certificate and asymmetric key sources.

I still do not understand how do I use a login created from these sources and what difference does it make from a normal login.

Regards,

Ravi

|||

Logins mapped to certificates or asymmetric keys cannot be used for authentication with SQL Server - you cannot login with them. These logins are used to assign server-level permissions to the certificates/asymmetric keys that are mapped to them, which is useful for signing; that is their sole purpose. For an example of use, see the following example:

http://blogs.msdn.com/lcris/archive/2005/06/15/429631.aspx

Thanks
Laurentiu

|||

Thanks a lot. It helped me in understanding their usage.

Regards,

Ravi

Wednesday, March 21, 2012

Login failed for the user (using windows integrated security)

Hello Everyone,

I am trying to connect SQL database through code but I get this error,I have spent days to solve it but unfortunately I couldn't...Here is my code in VB express(OP:windows 2000 with SP4)I am new to VB,so it makes the situation more difficult for me.

my code is:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn1 As SqlConnection = _

New SqlConnection("Data Source=.\SQLEXPRESS;" & _

"Integrated Security=SSPI;" & _

"database=deneme3_database;")

'Open connection

conn1.Open()

MessageBox.Show("Connection succeeded.")

'Close connection

conn1.Close()

MessageBox.Show("Connection closed.")

End Sub

The error message is,it is in german but it is clear I guess:)

" Die von der Anmeldung angeforderte "deneme3_database"-Datenbank kann nicht ge?ffnet werden. Fehler bei der Anmeldung.
Fehler bei der Anmeldung für den Benutzer 'ADPLAN\atalay'. "

Thank you in advance!

Can

The database mentioned in the connection string under database or Initial catalog is not present on the server or not accessible to the user. So either grant additional rights to the user or choose another database for the initial connection.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Hallo,

First of all I'd like to thank you for your reply.

The mentioned database was also created by me ,using new project in VB express and was also saved on the same PC. I don't actually know how to get permission to use it...I am new to VB and SQL so it makes the things a bit difficult for me.I also enable TCP/IP connection and pipes in SQL Express Server and also disabled the firewall but anyway I get the same error...

I have to write a program connecting to an external device and get the data from the device and compare it with the data in SQL database.But I stucked in the beginning...

Regards,

Can

|||

For a quick one, try to add the user to the sysadmin group to let him access the database (if it is based on a security issue)

sp_addsrvrolemember [ @.loginame= ] 'login'
, [ @.rolename = ] 'role'


For granular configuration, use the following procedure to grant him access to the db (not any objects so far)

sp_grantlogin [@.loginame=] 'login'
sp_defaultdb [ @.loginame = ] 'login', [ @.defdb = ] 'database'
sp_grantdbaccess [ @.loginame = ] 'login'
[ , [ @.name_in_db = ] 'name_in_db' [ OUTPUT ] ]

The same can be done within the Managment Studio.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de


|||

Hi Mr. Suessmeyer,

Again thank you for your reply...But I don't know where to enter this code in SSMS...It'd be kind of you you if you could explain it to me a bit more detailed.I am new to SQL and VB...Thank you!

Can

|||

hi Can,

outcast1881 wrote:

Hi Mr. Suessmeyer,

Again thank you for your reply...But I don't know where to enter this code in SSMS...It'd be kind of you you if you could explain it to me a bit more detailed.I am new to SQL and VB...Thank you!

Can

you can execute the statemets Jens provided via any tool able to send command to SQL Server... for your convenience, you can download and use SQL Server Management Studio Express, the free graphical management tool for SQLExpress at http://www.microsoft.com/downloads/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796&displaylang=en..

after connecting to the required SQL Server instance, you can open a "new query" window and execute them...

the very same tool provides a graphical interface to manage Logins, database Users and the like..

regards

Login failed for the user (using windows integrated security)

Hello Everyone,

I am trying to connect SQL database through code but I get this error,I have spent days to solve it but unfortunately I couldn't...Here is my code in VB express(OP:windows 2000 with SP4)I am new to VB,so it makes the situation more difficult for me.

my code is:

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim conn1 As SqlConnection = _

New SqlConnection("Data Source=.\SQLEXPRESS;" & _

"Integrated Security=SSPI;" & _

"database=deneme3_database;")

'Open connection

conn1.Open()

MessageBox.Show("Connection succeeded.")

'Close connection

conn1.Close()

MessageBox.Show("Connection closed.")

End Sub

The error message is,it is in german but it is clear I guess:)

" Die von der Anmeldung angeforderte "deneme3_database"-Datenbank kann nicht ge?ffnet werden. Fehler bei der Anmeldung.
Fehler bei der Anmeldung für den Benutzer 'ADPLAN\atalay'. "

Thank you in advance!

Can

The database mentioned in the connection string under database or Initial catalog is not present on the server or not accessible to the user. So either grant additional rights to the user or choose another database for the initial connection.

HTH, Jens Suessmeyer.

http://www.sqlserver2005.de

|||

Hallo,

First of all I'd like to thank you for your reply.

The mentioned database was also created by me ,using new project in VB express and was also saved on the same PC. I don't actually know how to get permission to use it...I am new to VB and SQL so it makes the things a bit difficult for me.I also enable TCP/IP connection and pipes in SQL Express Server and also disabled the firewall but anyway I get the same error...

I have to write a program connecting to an external device and get the data from the device and compare it with the data in SQL database.But I stucked in the beginning...

Regards,

Can

|||

For a quick one, try to add the user to the sysadmin group to let him access the database (if it is based on a security issue)

sp_addsrvrolemember [ @.loginame= ] 'login'
, [ @.rolename = ] 'role'


For granular configuration, use the following procedure to grant him access to the db (not any objects so far)

sp_grantlogin [@.loginame=] 'login'
sp_defaultdb [ @.loginame = ] 'login', [ @.defdb = ] 'database'
sp_grantdbaccess [ @.loginame = ] 'login'
[ , [ @.name_in_db = ] 'name_in_db' [ OUTPUT ] ]

The same can be done within the Managment Studio.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de


|||

Hi Mr. Suessmeyer,

Again thank you for your reply...But I don't know where to enter this code in SSMS...It'd be kind of you you if you could explain it to me a bit more detailed.I am new to SQL and VB...Thank you!

Can

|||

hi Can,

outcast1881 wrote:

Hi Mr. Suessmeyer,

Again thank you for your reply...But I don't know where to enter this code in SSMS...It'd be kind of you you if you could explain it to me a bit more detailed.I am new to SQL and VB...Thank you!

Can

you can execute the statemets Jens provided via any tool able to send command to SQL Server... for your convenience, you can download and use SQL Server Management Studio Express, the free graphical management tool for SQLExpress at http://www.microsoft.com/downloads/details.aspx?familyid=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796&displaylang=en..

after connecting to the required SQL Server instance, you can open a "new query" window and execute them...

the very same tool provides a graphical interface to manage Logins, database Users and the like..

regards

Friday, February 24, 2012

Logic Question

Ok so I have a little problem. I dont want code or anything I just
want a little help with the logical steps to take to complete the
process.
Little background, we have students who come and take 10 courses to get
this certification. All 10 courses MUST be completed to get certified.
First I have three tables. tblStudent and tblCourse and
tblCourseCompleted.
tblStudent(StudentID) obviously contains all students enrolled,
tblCourse(CourseID) lists all courses offered(Only 10 courses
currently) and tblCourseCompleted lists the Student ID and Course ID
and Date the Course was completed.
So based off tblCourseCompleted i have a complete list of all the
students who have completed various courses.
BUT, What I want to do is generate a report that lists the which
courses the students HAVE NOT taken. So it needs to list Each student
and every course hes missing. So if student A is missing 4 courses, it
will list student A four times with each course he has not yet
completed.
So basically i need the EXACT opposite of tblCourseCompletions.
Can anyone help me with the logic of some how generating this type of
report?Sometimes it is simpler to explain logic with an example:
SELECT *
FROM tblStudent as S
CROSS JOIN tblCourse as C
WHERE NOT EXISTS
(select * from tblCourseCompleted as X
where X.course = C.course
and X.student = S.student)
The cross join gives every possible combination of student and course.
The NOT EXISTS correlated subquery eliminates those that have been
completed.
Roy Harvey
Beacon Falls, CT
On 12 Jul 2006 08:55:23 -0700, "wmureports" <justin.a.moran@.gmail.com>
wrote:

>Ok so I have a little problem. I dont want code or anything I just
>want a little help with the logical steps to take to complete the
>process.
>Little background, we have students who come and take 10 courses to get
>this certification. All 10 courses MUST be completed to get certified.
>First I have three tables. tblStudent and tblCourse and
>tblCourseCompleted.
>tblStudent(StudentID) obviously contains all students enrolled,
>tblCourse(CourseID) lists all courses offered(Only 10 courses
>currently) and tblCourseCompleted lists the Student ID and Course ID
>and Date the Course was completed.
>So based off tblCourseCompleted i have a complete list of all the
>students who have completed various courses.
>BUT, What I want to do is generate a report that lists the which
>courses the students HAVE NOT taken. So it needs to list Each student
>and every course hes missing. So if student A is missing 4 courses, it
>will list student A four times with each course he has not yet
>completed.
>So basically i need the EXACT opposite of tblCourseCompletions.
>Can anyone help me with the logic of some how generating this type of
>report?|||Try,
select t1.*
from
(
select a.StudentID, b.CourseID
from tblStudent as a cross join tblCourse as b
) as t1
where not exists(
select *
from tblCourseCompleted as t2
where t2.StudentID = t1.StudentID and t2.CourseID = t1.CourseID
)
AMB
"wmureports" wrote:

> Ok so I have a little problem. I dont want code or anything I just
> want a little help with the logical steps to take to complete the
> process.
> Little background, we have students who come and take 10 courses to get
> this certification. All 10 courses MUST be completed to get certified.
> First I have three tables. tblStudent and tblCourse and
> tblCourseCompleted.
> tblStudent(StudentID) obviously contains all students enrolled,
> tblCourse(CourseID) lists all courses offered(Only 10 courses
> currently) and tblCourseCompleted lists the Student ID and Course ID
> and Date the Course was completed.
> So based off tblCourseCompleted i have a complete list of all the
> students who have completed various courses.
> BUT, What I want to do is generate a report that lists the which
> courses the students HAVE NOT taken. So it needs to list Each student
> and every course hes missing. So if student A is missing 4 courses, it
> will list student A four times with each course he has not yet
> completed.
> So basically i need the EXACT opposite of tblCourseCompletions.
> Can anyone help me with the logic of some how generating this type of
> report?
>|||From a logic point of view , you want to SELECT courses per student NOT IN
the tblCoursesCompalted.
The way you'be described the first report would be using an INNER JOIN , i.e
only display the record , if it exists as a
relationship in the tblCourseCompleted . On a logic level, you need to find
the set that doesn't have a relationship in that table.
You could use a LEFT OUTER JOIN and then put a condition on the WHERE
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"wmureports" <justin.a.moran@.gmail.com> wrote in message
news:1152719723.696320.29420@.75g2000cwc.googlegroups.com...
> Ok so I have a little problem. I dont want code or anything I just
> want a little help with the logical steps to take to complete the
> process.
> Little background, we have students who come and take 10 courses to get
> this certification. All 10 courses MUST be completed to get certified.
> First I have three tables. tblStudent and tblCourse and
> tblCourseCompleted.
> tblStudent(StudentID) obviously contains all students enrolled,
> tblCourse(CourseID) lists all courses offered(Only 10 courses
> currently) and tblCourseCompleted lists the Student ID and Course ID
> and Date the Course was completed.
> So based off tblCourseCompleted i have a complete list of all the
> students who have completed various courses.
> BUT, What I want to do is generate a report that lists the which
> courses the students HAVE NOT taken. So it needs to list Each student
> and every course hes missing. So if student A is missing 4 courses, it
> will list student A four times with each course he has not yet
> completed.
> So basically i need the EXACT opposite of tblCourseCompletions.
> Can anyone help me with the logic of some how generating this type of
> report?
>|||OK that worked PERFECTLY! thank you very much
Roy Harvey wrote:[vbcol=seagreen]
> Sometimes it is simpler to explain logic with an example:
> SELECT *
> FROM tblStudent as S
> CROSS JOIN tblCourse as C
> WHERE NOT EXISTS
> (select * from tblCourseCompleted as X
> where X.course = C.course
> and X.student = S.student)
> The cross join gives every possible combination of student and course.
> The NOT EXISTS correlated subquery eliminates those that have been
> completed.
> Roy Harvey
> Beacon Falls, CT
> On 12 Jul 2006 08:55:23 -0700, "wmureports" <justin.a.moran@.gmail.com>
> wrote:
>

Logic Question

Ok so I have a little problem. I dont want code or anything I just
want a little help with the logical steps to take to complete the
process.
Little background, we have students who come and take 10 courses to get
this certification. All 10 courses MUST be completed to get certified.
First I have three tables. tblStudent and tblCourse and
tblCourseCompleted.
tblStudent(StudentID) obviously contains all students enrolled,
tblCourse(CourseID) lists all courses offered(Only 10 courses
currently) and tblCourseCompleted lists the Student ID and Course ID
and Date the Course was completed.
So based off tblCourseCompleted i have a complete list of all the
students who have completed various courses.
BUT, What I want to do is generate a report that lists the which
courses the students HAVE NOT taken. So it needs to list Each student
and every course hes missing. So if student A is missing 4 courses, it
will list student A four times with each course he has not yet
completed.
So basically i need the EXACT opposite of tblCourseCompletions.
Can anyone help me with the logic of some how generating this type of
report?Sometimes it is simpler to explain logic with an example:
SELECT *
FROM tblStudent as S
CROSS JOIN tblCourse as C
WHERE NOT EXISTS
(select * from tblCourseCompleted as X
where X.course = C.course
and X.student = S.student)
The cross join gives every possible combination of student and course.
The NOT EXISTS correlated subquery eliminates those that have been
completed.
Roy Harvey
Beacon Falls, CT
On 12 Jul 2006 08:55:23 -0700, "wmureports" <justin.a.moran@.gmail.com>
wrote:
>Ok so I have a little problem. I dont want code or anything I just
>want a little help with the logical steps to take to complete the
>process.
>Little background, we have students who come and take 10 courses to get
>this certification. All 10 courses MUST be completed to get certified.
>First I have three tables. tblStudent and tblCourse and
>tblCourseCompleted.
>tblStudent(StudentID) obviously contains all students enrolled,
>tblCourse(CourseID) lists all courses offered(Only 10 courses
>currently) and tblCourseCompleted lists the Student ID and Course ID
>and Date the Course was completed.
>So based off tblCourseCompleted i have a complete list of all the
>students who have completed various courses.
>BUT, What I want to do is generate a report that lists the which
>courses the students HAVE NOT taken. So it needs to list Each student
>and every course hes missing. So if student A is missing 4 courses, it
>will list student A four times with each course he has not yet
>completed.
>So basically i need the EXACT opposite of tblCourseCompletions.
>Can anyone help me with the logic of some how generating this type of
>report?|||Try,
select t1.*
from
(
select a.StudentID, b.CourseID
from tblStudent as a cross join tblCourse as b
) as t1
where not exists(
select *
from tblCourseCompleted as t2
where t2.StudentID = t1.StudentID and t2.CourseID = t1.CourseID
)
AMB
"wmureports" wrote:
> Ok so I have a little problem. I dont want code or anything I just
> want a little help with the logical steps to take to complete the
> process.
> Little background, we have students who come and take 10 courses to get
> this certification. All 10 courses MUST be completed to get certified.
> First I have three tables. tblStudent and tblCourse and
> tblCourseCompleted.
> tblStudent(StudentID) obviously contains all students enrolled,
> tblCourse(CourseID) lists all courses offered(Only 10 courses
> currently) and tblCourseCompleted lists the Student ID and Course ID
> and Date the Course was completed.
> So based off tblCourseCompleted i have a complete list of all the
> students who have completed various courses.
> BUT, What I want to do is generate a report that lists the which
> courses the students HAVE NOT taken. So it needs to list Each student
> and every course hes missing. So if student A is missing 4 courses, it
> will list student A four times with each course he has not yet
> completed.
> So basically i need the EXACT opposite of tblCourseCompletions.
> Can anyone help me with the logic of some how generating this type of
> report?
>|||From a logic point of view , you want to SELECT courses per student NOT IN
the tblCoursesCompalted.
The way you'be described the first report would be using an INNER JOIN , i.e
only display the record , if it exists as a
relationship in the tblCourseCompleted . On a logic level, you need to find
the set that doesn't have a relationship in that table.
You could use a LEFT OUTER JOIN and then put a condition on the WHERE
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________
"wmureports" <justin.a.moran@.gmail.com> wrote in message
news:1152719723.696320.29420@.75g2000cwc.googlegroups.com...
> Ok so I have a little problem. I dont want code or anything I just
> want a little help with the logical steps to take to complete the
> process.
> Little background, we have students who come and take 10 courses to get
> this certification. All 10 courses MUST be completed to get certified.
> First I have three tables. tblStudent and tblCourse and
> tblCourseCompleted.
> tblStudent(StudentID) obviously contains all students enrolled,
> tblCourse(CourseID) lists all courses offered(Only 10 courses
> currently) and tblCourseCompleted lists the Student ID and Course ID
> and Date the Course was completed.
> So based off tblCourseCompleted i have a complete list of all the
> students who have completed various courses.
> BUT, What I want to do is generate a report that lists the which
> courses the students HAVE NOT taken. So it needs to list Each student
> and every course hes missing. So if student A is missing 4 courses, it
> will list student A four times with each course he has not yet
> completed.
> So basically i need the EXACT opposite of tblCourseCompletions.
> Can anyone help me with the logic of some how generating this type of
> report?
>|||OK that worked PERFECTLY! thank you very much :)
Roy Harvey wrote:
> Sometimes it is simpler to explain logic with an example:
> SELECT *
> FROM tblStudent as S
> CROSS JOIN tblCourse as C
> WHERE NOT EXISTS
> (select * from tblCourseCompleted as X
> where X.course = C.course
> and X.student = S.student)
> The cross join gives every possible combination of student and course.
> The NOT EXISTS correlated subquery eliminates those that have been
> completed.
> Roy Harvey
> Beacon Falls, CT
> On 12 Jul 2006 08:55:23 -0700, "wmureports" <justin.a.moran@.gmail.com>
> wrote:
> >Ok so I have a little problem. I dont want code or anything I just
> >want a little help with the logical steps to take to complete the
> >process.
> >
> >Little background, we have students who come and take 10 courses to get
> >this certification. All 10 courses MUST be completed to get certified.
> >
> >First I have three tables. tblStudent and tblCourse and
> >tblCourseCompleted.
> >
> >tblStudent(StudentID) obviously contains all students enrolled,
> >tblCourse(CourseID) lists all courses offered(Only 10 courses
> >currently) and tblCourseCompleted lists the Student ID and Course ID
> >and Date the Course was completed.
> >
> >So based off tblCourseCompleted i have a complete list of all the
> >students who have completed various courses.
> >
> >BUT, What I want to do is generate a report that lists the which
> >courses the students HAVE NOT taken. So it needs to list Each student
> >and every course hes missing. So if student A is missing 4 courses, it
> >will list student A four times with each course he has not yet
> >completed.
> >
> >So basically i need the EXACT opposite of tblCourseCompletions.
> >
> >Can anyone help me with the logic of some how generating this type of
> >report?

Monday, February 20, 2012

logging the DDL stmts

Hi :

I am using .cmd files to execute .sql files.

sqlcmd is used in .cmd files to execute the .sql stmts.

In .cmd file the sqlcmd line of code is as follows:

sqlcmd -i .\..\..\sql\tables\create_employee_table.sql

In .sql file the ddl stmt is as follows:

CREATE TABLE [Employee](
[EmployeeID] [int] IDENTITY(1,1) NOT NULL,
[NationalIDNumber] [nvarchar](15) COLLATE Latin1_General_CS_AI NOT NULL,
[ContactID] [int] NOT NULL,
[LoginID] [nvarchar](256) COLLATE Latin1_General_CS_AI NOT NULL,
[ManagerID] [int] NULL,
DF_Employee_rowguid] DEFAULT (newid()),
[ModifiedDate] [datetime] NOT NULL CONSTRAINT CONSTRAINT [PK_Employee_EmployeeID] PRIMARY KEY CLUSTERED
(
[EmployeeID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

DDL used are create and drop of tables and indexes.

How do i log all the ddl stmts executed into some .log file (xyz.log)?

The log file should read something like,

employee table created sucessfully

employee table dropped sucessfully.

...................

sqlcmd -o c:\log\xyz.log , gives me only the output for dml stmts (like select * from emp).. anything other than this will be very helpful.

Any solutions will be of great help.

This is a broader SQL question than just SQL Express so I'm moving it to the Database Engine forum; I think you'll find a better answer there.

In looking around a bit, I found information about DDL Triggers which would seem to do what you suggest. The folks in the other forum can validate my guess.

Regards,

Mike Wachal
SQL Express team

-
Check out my tips for getting your answer faster and how to ask a good question: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=307712&SiteID=1

|||

From the sounds of it you just want output in a text file to know whether or not your create table statement succeeded or not. DDL triggers can do this on the server, however if you have malformed sql (as in your post) or just want to log out to a text file directly from sqlcmd have a look at the -r parameter

sqlcmd -icreate_employee_table.sql -S. -E -o create_employee_table.log -r1

The file "create_employee_table.log" will contain output like this:

Msg 102, Level 15, State 1, Server name, Line 7
Incorrect syntax near ']'.
Msg 319, Level 15, State 1, Server name, Line 11
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.

To print out success messages you'll need to actually check the value of the @.@.error in the script and print out an appropriate message.

CREATE TABLE [Employee](
[EmployeeID] int IDENTITY(1,1) NOT NULL,
[NationalIDNumber] nvarchar(15) COLLATE Latin1_General_CS_AI NOT NULL,
[ContactID] int NOT NULL,
[LoginID] nvarchar(256) COLLATE Latin1_General_CS_AI NOT NULL,
[ManagerID] int NULL,
[DF_Employee_rowguid] UNIQUEIDENTIFIER DEFAULT (newid()),
[ModifiedDate] datetime NOT NULL CONSTRAINT [PK_Employee_EmployeeID] PRIMARY KEY CLUSTERED
(
[EmployeeID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

if @.@.error = 0
print 'employee table created sucessfully'