ASP.Net - Cannot open database "Database Name" requested by the login - sql-server-express

I'm working on a website in Visual Studio 2010 Ultimate using SQL Server 2008 R2 Express edition(x64) on a Windows 7 Home Premium(x64) laptop.
After Debugging i am getting an error-
Cannot open database "Edufun.mdf" requested by the login. The login failed.
Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.
Edufun is my database name. I have tried various solution like setting up a login via SQL Server management studio, making NT AUTHORITY\NETWORK SERVICE db_owner of my database. Changed my connection string various times by various methods. Also given Read and Write Permission to Network Service to the database. My connection string is same in IIS and WEB.Config.
I have seen various solution but nothing worked my connection string is =
name="connection" "Server=RUSTY\SQLEXPRESS;Database=Edufun.mdf;
Integrated Security=true" providerName="System.Data.SqlClient"
Rusty is my PC name an during SQL Server installation i had created default instance by the name SQLExpress.
please help me out with this if anybody need the stack trace tell me i will post it.
thank You in Advance

Related

SQL Server 2008 r2 can't login

I am working on Windows Server 2003 using SQL Server 2008 R2 and the .NET Framework 4.
My problem
I can't login to my database from my website although I can login from my Management Studio
I created a login named William.
My connection string is
<add name="TestDbConnectionString"
connectionString="Data Source=(local);Initial Catalog=RESv5;User Id=William;Password=MYPASSWORD;"
providerName="System.Data.SqlClient" />
I got this error:
Login failed for user 'William'
NOTE:
The same username and password I use in the Management Studio and I can login.
Are the website, the SQL Server instance, and SSMS all running on your local machine?
If they are not the same machine, then that is probably the source of the problem: "(local)" on a different machine will mean something different than "(local)" on your own personal laptop.
Try this for the Data Source portion of the name:
Data Source=LocalServerName
... where LocalServerName is the name of the server on which the SQL Server instance is running. If the database is on your machine and the website is elsewhere, use the name of your machine for LocalServerName.
ETA: If you have more than one SQL Server instance running and the one you want is NOT named MSSQLSERVER, you would reference it like this:
Data Source=.\SQLEXPRESS
As marc_s points out, if the instance is called MSSQLSERVER, you can use (local) as you are doing, or
Data Source=.

Login failed for SQL Server user

I know this question has been asked before on here, but none of the solutions seem to have helped. I am migrating a database from one machine hosting SQL Server 2008 Express to another. Basically the exact same configuration. I backed up my database from Old Server to New Server. When I try to run my application, I'm told "Login failed for user 'sqluser'." I've compared the settings from Old Server and New Server and they are identical as far as I can tell. If it helps, here is my connection string:
<add name="RetailCrimeConnectionString" connectionString="Data Source=NewServer\SQLEXPRESS;Initial Catalog=RetailCrime;Persist Security Info=True;User ID=sqluser;Password=AwesomePassword"
providerName="System.Data.SqlClient" />
If I switch the connection string back to OldServer, my application is happy again.
The user sqluser is datareader and datawriter on RetailCrime -- just like he is on OldServer. The application is clearly connecting because the error changes to a connection error if I change the data source to something purposely incorrect. I've gone through the SQL instance settings and I think everything that needs to be enabled is enabled. I've even added a firewall exception (a step I didn't need to take on OldServer). And I have re-created the database and created a test one on NewServer with the same results.
Is there anything outside the normal fare of Google results that I may have missed? Let me know if there is any other info you need. I wasn't sure what other details to include.
Thanks!
I figured it out. It turns out that I set the server to only accept Windows authentication and not SQL Server accounts when I set it up. Once I set that in SMSS, the web application started accepting SQL login with no trouble. I came to this idea when I realized that I could connect by impersonating Windows accounts. Thanks for the ideas! Merry Christmas!
Have you created the SQL Login for sqluser and mapped it to the database user?
You only mention the database user in your question.
Try deleting "NewServer", and add "." instead. If it's not on the same machine, put IP address of NewServer in place of the ".", like "Data Source=10.10.46.15\SQLExpress". Like below:
<add name="RetailCrimeConnectionString"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=RetailCrime;Persist Security Info=True;
User ID=sqluser;Password=AwesomePassword" providerName="System.Data.SqlClient" />
You also need to make sure your TCP/IP communication is enabled. This is for 2012 but step should be similar, See steps:
On the Start menu, click All Programs > Microsoft SQL Server 2012 >
Configuration Tools > SQL Server Configuration Manager.
Click SQL Server 2012 Services.
Expand the SQL Server 2012 Network Configuration node, and then
select Protocols for MSSQLServer (SQL Instance Name).
Right-click TCP/IP, and then click Enable.
Select SQL Server 2012 Services in the tree.
Right-click SQL Server (SQL Instance Name), and then click Restart.
Update:
Last thing to try, maybe:
Go to Start > Microsoft SQL Sever 2012 folder > Configuration Tools > Open SQL Server Configuration Manager
Make sure everything on the list in SQL Server Services is not Stopped. And make sure the start Mode is set to Automatic, not manual.

MSSQL login authentication problems with ODBC connection and R stats package

I am trying to connect an ODBC source to the R statistical package but having log in problems.
I have set up the ODBC name eplR with an SQL server driver linking to the (local) server using windows NT authentication with the network login ID default. In the set up the data-source test is successful.
When I try and create the connection in R
library(RODBC)
channel <- odbcConnect("eplR")
I get a failed connection
Login failed for user pssguy-PC/pssguy - my local computer name
When I connect to the (local) SQL server 2005 via management studio with Windows authentication I get a similar error unless I open management studio
with the "run as administrator" option.
In management studio, if I look at the properties of the (local) server, the authentication is set to Windows authentication mode.
The permission to connect SQL grantor is sa and the Grant box is checked. There is also a connect sql permission for pssguy-PC\pssguy with an unchecked box. I check it but on restarting mssql server it has reverted to unchecked.
I had what I thought was an identical setup on another standalone machine and I have no problems connecting in R.
Any help much appreciated
Maybe with odbcConnect() you could try passing the uid and pwd arguments too?
i.e.
odbcConnect("eplR", "**USERNAME**", "**PASSWORd**")

"Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'." to SQL Server 2005

I'm trying to migrate a legacy application we have to Windows Server 2008 x64 and IIS7. It's written in Classic ASP and connects to a SQL Server 2005 database.
However, when the page runs, I receive the error:
[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
The connection string I'm using is: Driver=SQL Server; Server=SERVERNAME; Initial Catalog=DBNAME;
I can't see any reason for it to be using the anonymous logon as when it was running on my 32-bit Win2k3 server, it accessed the SQL Server using DOMAINNAME\SERVERNAME$.
I have the following settings.
SQL Server 2005 - running in mixed mode.
IIS7 Application Pool - Allow 32-bit applications set to True.
I've also added the server as a user on the SQL Server.
I've tried a few things now and I'm starting to run out of ideas.
There are some solutions.
use SQL authentication, instead of SSPI. It will work since your database is in mixed mode.
If for any reasons you won't change the authentication.
The NT AUTHORITY\ANONYMOUS LOGON is strange, by the way, just as if the database server and the app servers are not on the same domain. Please check this until proeding further.
1) Create an user in Active Directory
2) Create a application pool on IIS7 and as "Identity" , the user you've created
3) Grant this user the rights and roles you want on the DB
I think I've fixed it. Moving to Win2k8 means that I needed to change the connection string driver to SQL Native Client;.
Set the Anonymous Authentication credentials to be your Application Pool Identity.
(default is Specific User --> IIS User). Then you can use a Trusted Connection in your connection string as it will now use the AppPoolIdentity account.
Well, that failed login attempt is a classic example of code running under the "Local Service" account, rather than (what you had on Win2K3), where it was running under the "Network Service" account. Now you just need to find where that setting is.
For either the OP or future readers, you can:
1) Either use a dedicated service account, as suggested by Johan above, or
2) Use the AppPoolIdentity account and go to "Authentication", then select "Windows Authentication" and enable "ASP .NET Impersonation".
If you still get the same result after #2, you likely have the "double hop" issue cited by Damien - this is where the web server can authenticate you, but it does not allow you to pass those credentials on to the database for security reasons without using Kerberos. You would then need to set the server as "Trusted for Delegation" in AD and set up Kerberos as the authentication provider in IIS. This site helps with that: http://technet.microsoft.com/en-us/library/ee675779.aspx

CF9 + SQL Server Express

I just created a new database in "Microsoft SQL Server Management Studio Express" and now I'm in "ColdFusion Administrator" and I'm trying to add my database as a Data Source. How do I do that? I believe the servername is .\SQLEXPRESS but I'm not sure what the default username and password are. I've tried creating a new login through Management Studio with an actual username and password, but those aren't working either. The error I'm getting is:
Connection verification failed for data source: xxx
java.sql.SQLNonTransientConnectionException: [Macromedia][SQLServer JDBC Driver]The requested instance is either invalid or not running.
The root cause was that: java.sql.SQLNonTransientConnectionException: [Macromedia][SQLServer JDBC Driver]The requested instance is either invalid or not running.
I can see that the service is running, and I can connect to it through management studio. I've tried following a couple tutorials online, but they don't seem to be working for me. Ideas?
Server name can be any resolvable hostname or domain name, in case of having SQL Server and CF server on same box localhost should work for you.
Also make sure that user you created has access to the particular database and needed operations. Look into the database permissions for this. This check is not required when using master account (often login is sa), but this is not recommended practice because of the security reasons.
Also make sure SQL Server and Windows Authentication mode is checked. I had an issue with permissions as well when I only had Windows Authentication enabled under:
right click on server (localhost) -> security
Then restart SQL Server Services to save changes. After that I was able to connect my ColdFusion datasource to SQL Server.
For testings sake use the same credentials that you are connected with in Management Studio, likely the "sa" user and password. Once you have it working with "sa" then go back into Management Studio and create an application level user for your CF app and then update the data source to use your new user / password.