I have installed SQL Server 2014 as well as Management Studio. Than I have imported database from .bkp file and try to make connection. My connection string looks like this.
<connectionStrings>
<add name="Name"
connectionString="server=PCNAME\SQLEXPRESS;database=DatabaseInMSSQL;User ID=sa;Password=password"
providerName="System.Data.SqlClient" />
</connectionStrings>
And this is error:
Cannot open database \"DatabaseName\" requested by the login. The
login failed.
Login failed for user 'sa'
Here is the code that I am using to connect
public void OpenConnection()
{
if (connection == null)
{
connection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["Name"].ConnectionString);
}
if (connection.State != ConnectionState.Open)
{
connection.Open();
}
}
I can login normally as well as windows auth, and SQL Server Authentication in SQL Server Management Studio with that password and user. My firewall is temporarily off!
I am using VS 2013 Community edition, and Windows 8.1 64bit
It would appear that the user sa (which you should never ever use for any kind of work anyways!) has a default database set as DatabaseName which doesn't exist.
How to fix it?
Login as sa or any other SQL Server system admin
Go to Object Explorer > Security > Logins > sa and right-click and select Properties
Change the default database for that user to something that does exist
Related
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.
using sql server managment studio I can connect database using sever authentication with
login = sa , password = 1
But I cant connect using server explorer (and from web app) in visual studio.
<add name="DefaultConnection" connectionString="Server=localhost;Database=XXX.mdf;Integrated Security=False;User Id=sa;Password=1"
providerName="System.Data.SqlClient" />
login failed for user sa
Can somebody answer this strange behavior?
I have 64bit Enterprize edition. Thanks.
Database=XXX.mdf
Is your database actually called XXX.mdf? I suspect it isn't, since that looks like a file name, and is perhaps just called XXX instead. The login will fail if the database isn't correct, since the server isn't going to give information about the failure to an unauthenticated user. Try:
Database=XXX
I just installed SQL Server 2012 Express edition on my computer (Windows 8).
When I try to create a database from the Management studio, I'm getting the following error:
Create failed for Database 'TestDB'. (Microsoft.SqlServer.Smo)
CREATE DATABASE permission denied in database 'master'.
(Microsoft SQL Server, Error: 262)
When I try to access it from the visual studio, I'm getting the following similar error message:
CREATE DATABASE permission denied in database 'master'.
Is there any reason for that? I can't even access the engine from the management studio.
EDIT
Here's my connection string
<add name="DefaultConnection"
connectionString="Data Source=localhost\sqlexpress;Initial
Catalog=OptimumWeightDB;Integrated Security=True;
Integrated Security=True;
User Id=sa;Password=mypassword" "
providerName="System.Data.SqlClient" />
This is the context class
public class OWDbContext : DbContext
{
public OWDbContext()
: base("DefaultConnection") { }
}
First of all. Try to log into SQL Management Studio on your SQL Server using Windows Authentication.
If you can create database / manipulate database using you windows account there maybe a problem on the security set up on your sa login account.
Then try to re create / create new login account and set its permission to db admin.
Other thing make sure that SQL server Authentication is Enabled on your SQL Server.
When you already connected to your SQL Server using Windows Authentication right click your SQL Server > Properties > Security > SQL server and Windows Authentication mode.
also change your connection string to
Data Source=localhost\sqlexpress; Initial Catalog=OptimumWeightDB; user=yourloginname; password=yourpassword;
Best Regards
first I have checked that Server Authentication is already set to:
"SQL server and Windows Authentication mode" (mixed mode)
้here 's my web.config connectionstring
<connectionStrings>
<add name="StockConnectionString" connectionString="Data Source=192.168.0.2;Initial Catalog=Stock;Persist Security Info=True;User ID=op;Password=operator" providerName="System.Data.SqlClient"/>
</connectionStrings>
Whene I test running (ctrl+F5) under VS2010 development this can connect to remote SQL server without any problem. but when i publish this project to local IIS (same web.config) an error occured..
Login failed for user 'op'. Reason:
Not associated with a trusted SQL
Server connection.
also i can connect to SQL server via SQL server Management Studio with SQL server authentication same user/pass.
no idea what's wrong with this.
finally, after 3 days can't figure this out. then i tried start over.
created a new project (ASP.NET MVC 2 web app) in VS2010.
go to Database Explorer > Add Connection..
use SQL server authentication to remote SQLserver directly instead of local.
then gotcha!! it told me..
this server version is not supported. you must have Microsoft SQL server 2005 or later.
my project was created under Win XP connect to SQLserver 2000 and it's work fine. now the answer for an error above is..
Visual Studio 2010 dropped support for SQL Server 2000. You'll either have to go back to VS2008/SL3, upgrade your SQL Server, or do things manually outside of Visual Studio.
...really appreciate this so much
Does it make any difference if you add this to the connection string ?
Trusted_Connection=False;
A clue is that it's saying that it's not trusted which indicates it's not using the username and password from the string. Has a connection string been possibly imported into IIS ?
Trusted is windows authentication which by the error is being used. Sql server authentication is username and password which you are trying to use.
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.