windows service sql connection problems - sql-server

I need your help !!!!
I want to connect to sql server from a windows service, but it throw following exception :
Login failed for user 'NT
AUTHORITY\ANONYMOUS LOGON'.
My connection string is declared as follow:
<add name="CoreConnectionString"
connectionString="Data Source=10.10.2.102;Initial Catalog=DataBaseName;
Integrated Security=True"
providerName="System.Data.SqlClient" />
When I use user name and password instead of Integrated Security=True It works but in final deployment I cannot use user name and password.
What is wrong what can I do????

When you define Integrated Security=True in your connection string, whatever user is currently logged in will try to connect to your database. When running this as a console or Winforms app, this is your own user account.
However, if you run it as a Windows NT Service, it's the service account that this service is running under - in your case obviuosly NT AUTHORITY\ANONYMOUS LOGON.
And the error says it clearly: this user account does not have the permission to connect to the SQL Server.
You have several options:
stop your NT service and change the service account to be someone who does have access to the SQL Server
allow the NT AUTHORITY\ANONYMOUS LOGON to log into your SQL Server and use your database
create a specific user (e.g. an "application user") in your SQL Server and change your connection string to use that user specifically:
connectionString="Data Source=10.10.2.102;Initial Catalog=DataBaseName;
user id=Your-Application-User-here;password=The-Secret-Password"

Related

"login failed for myuser" when changeing the connection string settings to use sql user

I've setting up an asp.net core application that use Identity.
With the default connectionstring, it works fine.
If I change the connection string (in the appsettings.json file), forcing it to use a specifed user to access the database, it doesn't work.
The working settings are:
"ConnectionStrings": {"DBContextConnection": "Server=myserver;Database=mydatabase;Trusted_Connection=True;MultipleActiveResultSets=true;Persist Security Info=True;"
}
Inspecting sql server in the working scenario (using activity monitor), user DOMAIN\myuser logged in successfully.
Changing the connection string settings as below (where myuser is a sql user, not a windows user), it doesn't work:
"ConnectionStrings": {"DBContextConnection": "Server=myserver; Database=mydb;User ID=myuser;Password=mypassword"}
With this configuration I get the following: login failed for myuser
The stranger things is that it doesn't work also using DOMAIN\myuser
PS: I can login with both user using sql server management studio and execute query on the aspnet tables.

Database Login Error

When I try to connect to database I get Database Login Error. The connection I use is "Data Source=IK-PC\\SQLEXPRESS;Initial Catalog='abc.new';Persist Security Info=True;User Id=IK-PC\\Administrator"
My server name: IK-PC\SQLEXPRESS
My authentication is Window Authentication
My user name is IK-PC\Administrator.
Everything is shown on SQL Management Studio Connect to Server form.And my database name is abc.new, which is attached to the SQLMS.
If you're using a Windows login in SQL Server, you should use Integrated Security=True (or Integrated Security=SSPI) instead of user Id and password.
"Data Source=IK-PC\\SQLEXPRESS;Initial Catalog='abc.new';Persist Security Info=True;Integrated Security=True"
You need to then run the process accessing SQL Server as IK-PC\Administrator user.

Visual Studio using wrong account to connect to SQL Server

I'm having trouble trying to get Visual Studio to connect to a database located on another server.
Here is my connection string :
<add name="CDDMSDB" connectionString="Database=CDDMS;Server=aecl-db01.domainx.local;Integrated Security=SSPI;Connection Timeout=7200"
providerName="System.Data.SqlClient" />
Now when I try to connect via my app, I get the following error :
Login failed for user 'DOMAINX\CDSDEV_NATHANIE$'.
The Account DOMAINX\CDSDEV_NATHANIE, does not exist. I am logged in under the account empower\nathanielp, but it does not seem to be using that account at all. I can connect to the SQL Server through Management Studio just fine using empower\nathanielp, but for whatever reason its not using that account when I run the app.
Any suggestions?
Thanks,
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28VS.71%29.aspx
According to this it is pulling your windows account credentials when you are trying to log into the database and that could explain the "The Account DOMAINX\CDSDEV_NATHANIE, does not exist." IF your windows account credentials doesn't exist on the server you are connecting too.
I would set Integrated Security=false and put the username and password you are logging into the server under in your connection string. using User ID= and Password= Hope this helps.

Cannot open database "Test" requested by the login. The login failed. Login failed for user 'DOMAIN\$Test'

After deploying a Linq to Sql Application in IIS ,the application throws this error.
Cannot open database "Test" requested by the login. The login failed. Login failed for user 'DOMAIN\$Test'.
It works perfectly fine in my development machine, following is my connection string
add key="Connection" value="Data Source=server-name;Initial Catalog=DbName;Integrated Security=SSPI"
The Account has enough permissions on Sql server.
Please help.
It got resolved..my bad...
The connection string was stored in the settings file which i didn't notice and it was pointing to dev. and windows account didn't have permission.
Thanks...

What is the default username and password of my SQL Server Express?

It installed automatically with Visual Studio 2010 Ultimate. I didn't create any users for the server or ANYTHING.
I'm using:
string connectionString = #"Server=.\SQLEXPRESS;Database=SportsStore;Trusted_Connection=yes;";
I get error that authentication failed. So the server is being found, but my credentials are wrong. What would the default login and password be?
Edit: Still not working! :(
Here's my connection string:
string connectionString = #"Server=.\SQLEXPRESS;Database=SportsStore;Integrated Security=SSPI;";
And the error message:
Cannot open database "SportsStore"
requested by the login. The login
failed. Login failed for user
'ToshibaLaptop\Sergio'.
If you are using SQL Server authentication you could try the username sa and blank password but I am not sure whether this is by default. Integrated Windows authentication should work, so you should be able to connect with your Windows account:
string conn = "Data Source=.\SQLExpress;Initial Catalog=mydb;Integrated Security=SSPI;";
You probably should not connect using Sql Server Authentication.
Log in as an Administrator on the box, connect using Integrated Windows Authentication, and you should be a system admin.
The error message indicates that SQL Server can't open the database. I think you're successfully authenticating, but having a problem connecting to the database. Is the database available?
You can do a test by changing the database to master in your connection string. If that succeeds, then you're problem is related to the database. I understand that you may get other errors, but the test is to confirm that you can login to SQL Server.
For me SQL Server (SQLEXPRESS) service was disabled so it was throwing the error. After enabling the service SSMS is working fine
Goto Run command and type services.msc and click on OK button
Services window will open. Check the status of SQL Server (SQLEXPRESS) service
If the service is not running, then start the service
Now try logging in again in the SSMS.
In SQL 2008 if you use the defaults there won't be a SQL Server user only Windows Authentication will be enabled - and it will only work for the user that installed the application would have access via their Active Directory authentication.

Resources