I'm writing a VB.net application that runs off a SQL database. If the application can not connect to the database or the connection has not been set up I'm giving the user the option to create the database on the SQL server instance of their choice I then create the database and it's tables, dedicated user for the application to use and Stored Procedures. All this worked fine when testing yesterday including the user creation BUT for some reason, the User creation is throwing an error today. The Scripts I use to set up the user are as follows:
I run this Script on the master when logged in as an Server admin user.
CREATE LOGIN MyAppUser WITH PASSWORD ='UserPassword', DEFAULT DATABASE = MyAppDB
This sets up the SQL Login I then run the following on the actual database to add the SQL Login to the Database User list:
CREATE USER MyAppUser FOR LOGIN MyAppUser
Unfortunately, I am now getting an error telling me the user, group or role already exists in the current database but if I look in the SQL Server, I can only see the user under the Server logins not under the Application Database Users. I'm going to try removing DEFAULT DATABASE setting but I understand this then just defaults to master.