Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone, I am really finding it hard to figure out this annoying issue with sql server logins. When I try to create a login in my wpf app, it works but I cannot use the username and password to authenticate via sql server authentication in my app. I have disabled the CHECK_POLICY, CHECK_EXPIRATION, MUST_CHANGE options yet, I can't still login. I tried to alter the login via sqlcommand object and it still the same. Then I went to my sql management studio and alter my login password and I tried to connect in my wpf app, and it works this time. The issue here is that, I want my wpf app to be able to do the alter statement because not all app users will have the management studio or they should only be allowed to download the sql server without the management studio which is done internally from the wpf app. Please guys, I need your help, its really urgent. Thanks
Posted

Check your connection string.
Try setting up a connection in VS with the Server Explorer pane:
1) Open Server Explorer.
2) Right click "Data connections" and select "Add connection"
3) In the dialog that follows, select your DataSource, and database, specify the security info, and press the "Test connection" button.
4) When the connection works, press "OK"
5) Highlight your database in the Server Explorer pane, and look at the Properties pane. A working example of the connection string will be shown, which you can copy and paste into your app or config file.
 
Share this answer
 
Comments
Member 10250878 12-Sep-15 9:22am    
Not still working.

I wrote this code in c# using sqlcommand object and it works. But, when I try to login with the credentials in my app, it doesn't work. It only works if I change my password or alter my password in sql management studio.

sqlcommand.commandTest:

CREATE LOGIN remoteUser
WITH PASSWORD = 'mypass123'; GO

-- Creates a database user for the login created above. CREATE USER remoteUser FOR LOGIN remoteUser GO
There shouldn't be any problems when changing password but you first need to establish a connection in order to change the password. Based on your description, the password you used was invalid until you changed it.

Once connected any SQL Server authenticated login can change it's own password using ALTER USER command. But if you need to change another users password, then you need to have ALTER ANY LOGIN privilege (or be a sysdamin).
 
Share this answer
 
Comments
Member 10250878 12-Sep-15 9:56am    
Hi mika, I can login from my app using windows authentication and sql server authentication only when i change my password in management studio. My code changes the integrated security at runtime and also generate connection strings. Its purpose is to support online or local (multiuser) connections. But, I am trying to change my password of my login I created in windows authentication mode and log in with the credentials In sql server authentication mode.
Wendelius 12-Sep-15 10:49am    
I'm sorry but I don't quite understand the scenario. First you connect using Windows authentication but then change to SQL Server authentication. This cannot be done using a single connection so it would require two separate connections. Also I don't see how changing password would affect this since the tool used to change password doesn't matter, only how the password is changed (new password, expiration, must change etc...)

Could you clarify the situation and the steps you have?
Member 10250878 12-Sep-15 13:20pm    
1) I connect using the default authentication which is Windows auth.
2) In the app there is a window that creates sql server login. On the submit button, it creates the login and gets the username and the login password from the textbox.
3) My code changes the connection string after creating the login(integrated security=false). Which means I can only login with credentials or sql server authentication.

Thats the process it follows. Then if I try to login it won't connect because I need to alter or change the login password. I wrote an alter query in my wpf app and it didn't work. Then I had to go 2 sql management studio to alter my login and tried it again in my wpf app, then it works.

I know your a little confused but the app works like sql management studio where you need to connect to a server first before you can do anything.
Wendelius 12-Sep-15 13:43pm    
Ok, I see. Based on your other comment you don't disable policy checking so that could cause the problem. Try modifying the program so that you use

CREATE LOGIN remoteUser
WITH PASSWORD = 'mypass123', CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF
I created a console app and tested it, and it works. I think its froum the connection string
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900