Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating users

Author  Topic 

mattswe
Starting Member

11 Posts

Posted - 2009-03-19 : 11:10:09
Hi!
Just installed SQL 2008 Server Express and I´m trying to access it from C++/CLI (VS2008 Express). Im logging in to SQL Server with Windows Integrated Security, and then I try to create a user in my database: create user matrikel for login ...
But when executing I get an error message: 'matrikel' is not a valid login or you do not have permission.

I think Im missing something in the concept.
I have to create a db user and then connect from my application with this user, right?
How to create this user? And what exactly is the "login" mentioned?

Best regards
Matt

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 11:12:40
does your logged in account have create user permission in db?
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-19 : 11:22:58
Well, my logged in account is found under DBinstance-Security-Logins (Object Explorer in Managed Studio), and it is the one called [computer name\Owner], right?

This one is sysadmin under Server roles.

Uh, Im not sure I know what Im talking about here...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 11:28:28
also does the specified sql login exists?
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-19 : 11:30:27
Im not sure i understand your question. What specified sql login?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 11:34:34
the login specified in

CREATE USER username FOR LOGIN loginname

blue part
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-19 : 11:40:16
Ok, now we´re talking. Im not sure what to make out of this loginname. What should I write there? I understand I have a logged in account, and I understand I try to create a db user. But what is this loginname?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 11:42:05
this is SQL login that you created in db which you're trying to map user to
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 11:45:39
if you've not created already, create one using CREATE LOGIN... statement

http://technet.microsoft.com/en-us/library/ms189751.aspx
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-19 : 12:08:28
Thanks! I managed to create a login and then an user.
But I still can´t connect from VS2008Express...
Go to Top of Page

NeilG
Aged Yak Warrior

530 Posts

Posted - 2009-03-19 : 12:33:44
did you grant the user any security rights
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-19 : 13:33:28
He got database role membership db_owner. Is that alright?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 14:14:28
yup...how are you trying to connect? whats the connection string used?
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-20 : 04:50:15
My connection string is like this:

Data Source=(local);Initial Catalog=Test;User Id=matrikel;Password=1234;

The SQL Server is running on my local computer and the database´s name is Test.
The db user is matrikel (database role: db_owner) and it is mapped to a login called Matt.

Still cant connect. Any ideas?
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-20 : 07:59:57
More specificly, this is what my code looks like (C++/CLI):

SqlConnectionv^ connection = gcnew SqlConnection();
connection->ConnectionString = "User ID=matrikel;Password=1234;"
"Data Source=(local);Initial Catalog=Test;";
try {
connection->Open();
...
}
catch(SqlException ^e) {
...
}
finally {
connection->Close();
}

When executing I end up in the catch clause.

I also have tried a connection string like this:
"Persist Security Info=False;Integrated Security=SSPI;Data Source=(local);Initial Catalog=Test;";

Im not really sure when to use this last one, anyway it doesnt work either.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-20 : 11:13:48
are you able to connect to server using sql login directly from sql management studio?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-20 : 11:14:48
also check if connection string used is correct

http://www.connectionstrings.com/sql-server-2008
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-20 : 13:56:20
Sorry, it´s over 5 years since I worked with databases last time.
How do I use sql login directly from sql management studio?

I´ve already checked with that site.
Go to Top of Page

mattswe
Starting Member

11 Posts

Posted - 2009-03-22 : 03:42:56
Ok, with Windows verifying I now can connect to the db with this connection string:

"Data Source=localhost\\SQLEXPRESS;Initial Catalog=Test;Integrated Security=SSPI;"

But I want to connect with SQL Server verifying (user and pwd). I´ve tried with following connection string but it doesnt connect:

"Data Source=localhost\\SQLEXPRESS;Initial Catalog=Test;User ID=matrikel;Password=1234;"

So, I guess something is wrong with my database user. But what?
How can I verify the user in SQL Server Managed Studio?
Go to Top of Page
   

- Advertisement -