SQL Server 2008 r2 can't login - sql

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=.

Related

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.

How to launch the SQL Server service in browser

I am new to SQL Server. I am doing the offline sync using SQL Server and sqlite DB. For that I followed the below tutorial SQL Server Installation. In this tutorial I am stuck on how to open the localhost service. When I run the service (localhost/AuroraSyncService.svc) in browser it shows empty.
For this I created the database AuroraSyncCn in my SQL Server Management Studio and created the new website in my IIS (internet information security).
MY coneection Strings:
<connectionStrings>
<add name="AuroraSyncCn" connectionString="Data Source=(local);Initial Catalog=SQLite-Sync.com;User ID=sa;Password=pass" providerName="System.Data.SqlClient" />
</connectionStrings>
here i tried connectionString="localhost/myservicefolde/aurorasyncservice.asmx;
Somebody help to solve this one.
From what I see your connection string should contain your database name (Initial Catalog=AuroraSyncCn).
If it's SQLExpress, instance name should probably be the same as the one mentioned by vasin1987 (server/serverinstance).
But from what I remember from ASP.NET, 'localhost' as Data Source should also be just fine.
Can you please show/write what you have in login window in MS SQL (Server name is what interest us the most):

Accessing Server under Windows 7 x64

we decided to start a new project using the Microsoft SQL Server R2 under Win7. I installed SQLEpress R2 on my system and it was decieded to called it BEACONExpress. At first we could not get it to run, until we had our Domain SysApp come in and set the ownership to my login. Now I was able to use SQL Management Studio to create the Database. I even added some Tables to it. Then I fired up VS 2010 and created a test program. When I try and access the new database, VS returns this error "The file can not be opened because it is being used by another process. Please close all applications that might access this file and try again."
If I attempt to create a new database under App_Data it returns this error. A network-related or instance-specific error occurered while establishing a connection to SQL server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified).
The connectionStrings in Web.config says
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename= |DataDirectory|aspnetdb.mdf;User Instance=true"
provideName=:System.Data.SqlClient" />
</connectStrings>
I found the database at C:\Program Files\Microsoft SQL Server\MSSQL10_50.BEACONEXPRESS\MSSQL\DATA\BeaconDB.mdf
I tried changing SQLEXPRESS to MSSQL10_50.BEACONEXPRESS but it had no affect. I have been reading here and on other forums trying to determine what is wrong but so far have not found an answer.
Have you verified that the Windows 7 firewall is configured to let you access the SQL Server? I had the same problem when triyng to access a database on my server at home, with Win7 x64.
Also, you should be sure to run the version SQL Server 2008 R2, because if R2 is not installed and all the updates are not installed, it will not work on Win7 x64
Maybe this link can help you:
http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/1bb10896-27ed-4469-81e0-a84f4fba68c9
http://blogs.msdn.com/b/sqlexpress/archive/2005/05/05/415084.aspx
Change your connection string element to
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=BeaconDB"
(Where BeaconDB is the name of your database)

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

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

SQL Server 2008 R2 First Time Login

I've just started work on a new computer in which I had to download all the software fresh.
I've just download a copy of SQL Server 2008 R2, and I'm trying to connect to SQL Server Management Studio without success. I vaguely remember last time I installed this, it asked me to choose between windows, or sql server authentication, however this didn't happen for this installation.
If I try to login via Windows Authentication (where the username and password fields are greyed out, localhost as server name) it gives the following error:
"A Network-related or instance
specific error occured while
establishing a connection to SQL
Server. The server was not found or
was not accessible. Verify that the
instance name is correct and that SQL
Server is configured to allow remote
connections. (provider: Named Pipes
Provider, error: 40 - Could not open a
connection to SQL Server) (Microsoft
SQL Server, Error: 2)"
I have checked everything in SQL Server Configuration Manager, and everything bar VIA is enabled.
If I try SQL Server Authentication, It asks me for a username and password which I definiately have not set yet. Also, under SQL Server Services in configuration manager, there is nothing there.
Any help would be appreciated :)
Thanks
PS: I don't know if it's worth mentioning but I am running Windows 7 as a virtual machine on a Mac.
Are you sure you have the correct instance name? If it was SQL Server 2008 R2 Express Edition then the default instance name is .\SQLEXPRESS.
Also if your using sql authentication to connect try running sql management studio as admin, if you are a limited user your identity might not be mapped to an account in sql server yet but i believe the Administrators user group is.
You need to check if your services are running.
Please type
net start mssqlserver
in your command prompt. Then try to login.
Ended up reinstalling completely and doing a fresh install from a fresh download. When I did this I was brought through the steps of selecting the default instance, and selecting authentication modes.
Working fine now :)
After checking tons of sites looking for an answer to this question, I think I have a simple solution.
Open the sql Server Configuration
Click on the sql server services node
Right Click on Sql server
Click Start.
I have been screwing around with this forever, and this simple method actually worked.