login failed connecting to SQL Server with AttachDbFilename and User Instance - sql-server-2005

I am developing ASP.NET 2.0 application using SQL Express 2005. I have attached my database with the application.
The Connection string:
<add name="WCMIRConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename="\App_Data\WCMIR.mdf";Integrated Security=True;Trusted_Connection=no;User Instance=True" />
When trying to connect the following error appears :
Cannot open database "dp-name" requested by the login. The login failed.
Login failed for user 'Machine\useID'.
How can this error be resolved?

First I think the connection string should be with |App_Data| not \App_Data\
Second Make sure that this user has permission on this folder and on this DB

You shouldn't need the AttachDbFileName if your database is already attached, but you should include InitialCatalog to indicate which database you would like to connect to.

Problem Solved
Connection string must be like :
Data Source=.\SQLEXPRESS;AttachDbFileName=|DataDirectory|DB.MDF;" +
"Integrated Security=True;User Instance=True";

Just try to use "|" instead of backslash in your code.

Related

ArgumentException: Keyword not supported: 'server'

I have an Asp.net MVC5 application and have published it to Microsoft Azure. I first migrated my .mdf files toSql Azure Databases. The database connection string provided in the Azure Portal is not working.
[ArgumentException: Keyword not supported: 'server'.]
My connection string is as follows web.config
connectionString="
Server=tcp:dbprojectserver.database.windows.net,1433;
Initial Catalog=db_project;
Persist Security Info=False;
User ID=username#servername;
Password=kenth&&123;
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=30;
"
I believe so there is something wrong with this connection string. Any help regarding that is highly appreciated.
EDIT
Reading from here SQL Server Connection Strings and following EF Db first or Model first connection string example
<add name="ConnectionStringName"
providerName="System.Data.EntityClient"
connectionString="metadata=res://*/ ContextClass.csdl|res://*/ ContextClass.ssdl|res://*/ ContextClass.msl;provider=System.Data.SqlClient;provider connection string="Data Source=ServerName;Integrated Security=False;User Id=userid;Password=password;MultipleActiveResultSets=True"" />
This is what I am using according to above example
<add name="ProjectEntities" connectionString="metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Integrated Security=False;User Id=username#servername;Password=kenth$$123;MultipleActiveResultSets=True"
" providerName="System.Data.EntityClient"/>
It says
Keyword not supported 'data source'
I had the same problem when specified EF connection string on the Azure Portal in Application Service settings (Application settings -> Connection strings).
To fix it:
Replace " with "
Specify connection string type as Custom but not as SQL Database.
Also, as I can see you do not have Initial Catalog in your latest example. You need to add it and specify your database in this parameter.
Finally your connection string for application settings in Azure portal should look like this:
metadata=res://*/ ProjectWeb.Models.User.csdl|res://*/ ProjectWeb.Models.User.ssdl|res://*/ ProjectWeb.Models.User.msl;
provider=System.Data.SqlClient;
provider connection string="Data Source=tcp:dbprojectserver.database.windows.net,1433;Initial Catalog=<your database>;Integrated Security=False;User Id=username#servername;Password=kenth$$123;MultipleActiveResultSets=True";

How to solve "Login failed for user 'domain\Username'" in SQL Server 2008 R2

I have a website where I need to fetch data from a SQL Server 2008 R2 database. But I'm getting an error
Login failed for user 'domain\Username'
I googled for it then I get that to change property of SQL Server -> Properties -> Security -> Server authentication to SQL Server and Windows authentication mode only I'm still getting the same error. I don't want to use ID and password in connection string
My connection string:
<add name="ConnectionString"
connectionString="Data Source=servername;Initial Catalog=databasename;Integrated Security=True"
providerName="System.Data.SqlClient" />
Please help me.
add user id and passsword
or
1) Go to Server Explorer tab on VS
2) In Data Connections right click (click on properties) on your db
3) copy Connection String

Database connectionstring windows authentication but passing user and password

I need some help.
I'm trying to connect to my database.
This is my connectionstring :
<add name="DefaultConnection" connectionString="Data Source=KBV-SQL12-TEST\KBSQLSPTEST; Initial Catalog=KBSPT_aspnetmembership; User Id=KBOVDM01\KBSPT_EXTRANET; Password=SPExtr#n3t" providerName="System.Data.SqlClient" />
The user is an Active Directory user.
When I go to my SQLServer and log on as KBSPT_EXTRANET, I can op the SQL Management Studio and connect to the database.
But in my application when I use the connectionstring mentionned above, I keep getting the message "Underlying provider failed on open".
What am I doing wrong?
You are trying to use a Windows account when the connection string is expecting a SQL Server user account.

Strange MVC Error Using GearHost

When I run my program on my local machine it works just fine. However, when I try to interact with my database via GearHost, I get this nugget of an error:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified.
Everywhere I have gone, the forums say it is a connection string error.
If that is the case here is my connection string:
<add name="GameStoreEntities" connectionString="metadata=res://*/Models.GamesModel.csdl|res://*/Models.GamesModel.ssdl|res://*/Models.GamesModel.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\GameStore.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
If anyone has any idea about what is wrong with the connection string, I would appreciate your feedback.
GearHost does not seem to have support for LocalDB.
So you would have to create a database on their admin panel and use the credentials of the default user that is created to write your connection string. You could also create a new user for the database and use those credentials instead.
Either way your new connection string should be something like this
<add name="GameStoreEntities"
providerName="System.Data.SqlClient"
connectionString="Data Source=DATABASEHOST;Initial Catalog=DATABASENAME;Integrated Security=False;User Id=USERNAME;Password=PASSWORD;MultipleActiveResultSets=True" />
where you just replace the DATABASEHOST with the hostname for the database. You would see this at the bottom of the page after creating the database.
You get the PASSWORD by clicking the uncover(eye) button after creating the database
If you have data in the localDB that you want to sync to the database you have created on GearHost you can use the Data Comparison and Schema Comparison tools in Visual Studio to update the target database.

What does App=EntityFramework do in Sql connection string?

I have 2 connection strings - 1 local and 1 for my main production server. Entity Framework added App=EntityFramework to my local string when I installed it (4.1) - I'm now on 4.3. What does this do - I can't find any reference to it?
Here's my local connection string:
<add name="LocalConnection"
providerName="System.Data.EntityClient"
connectionString="metadata=
res://*/;
provider=System.Data.SqlClient;
provider connection string='
Data Source=.\SQLEXPRESS;
AttachDBFilename=C:\mypath\MyDb.mdf;
Integrated Security=True;
User Instance=True;
MultipleActiveResultSets=True;
App=EntityFramework'" />
Just curious!
App and Application Name are simply a way for somebody debugging SQL Server to know which client is connecting to it. If you had a SQL Server that has several apps that used it, it might be hard to know which one was sending which statements. If each app used a different Application Name it would be very clear.
Check this out for more info.
It's just the synonym of the Application Name.
You can see the Connection String properties outlined here:
http://msdn.microsoft.com/en-gb/library/system.data.sqlclient.sqlconnection.connectionstring.aspx