I am trying to run some scripts from C# and I have a script createdb.sql.
When I execute it I get an error because login failed for mycompany\myname
This is the script
Use Master
-- Drop the database if it already exists
IF EXISTS (SELECT name
FROM sys.databases
WHERE name = N'TestDB')
BEGIN
ALTER DATABASE TestDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DROP DATABASE TestDB
CREATE DATABASE TestDB
ALTER DATABASE TestDB SET MULTI_USER
END
ELSE
BEGIN
CREATE DATABASE TestDB
What do I need to do to create a simple login as well?
Thanks
“mycompany\myname” looks like a domain login.
For “Windows security” SQL takes the currently logged on user, it’s difficult to impersonate another user to run SQL commands (but not impossible).
You can create a simpler SQL Login by following the instructions here this will allow you to supply credentials in the connection string