Cannot open database "name" requested by the login. The login failed - asp.net

I have deployed my web app on a server and I am trying to connect to a database on localdb. I am getting this error.
Cannot open database "hands.mdf" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\DefaultAppPool'.
I have created 'IIS APPPOOL\DefaultAppPool' login on the SQL server and given it access to all possible roles under user mapping.
This is my connection string:
<add name="constr" connectionString="Data Source=np:\\.\pipe\LOCALDB#D3DF8A08\tsql\query;Initial Catalog=hands.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
I have looked at similar requests and followed the advice with no luck. I have tried to change
"integrated security" to User ID=domain\administrator;pwd=password"
But still no luck.
Can someone help me with getting this working please?

Maybe 'IIS APPPOOL\DefaultAppPool' doesn't have permission to access hands.mdf directory.

All sorted problem was very simple at the end.
My original connection string was connecting to a local file i.e.
AttachDbFilename=hands.mdf
So when I changed to a attached SQL file
Initial Catalog=hands I should have removed (.mdf)

Related

cant log in to the database file on visual studio asp.net

net and SQL server so i am trying to do the code first approach after i created the models for the database and enable and add migrations on the packet manager when i update-database command in the packet manager it works fine but when i want to see the database in the server explorer i get the following error :
The attempt to attach to the database failed with the following information:
Login failed for user 'LAPTOP-U9AV480S\NS'.
and this is my web.config file with the connection string value
<connectionStrings>
<add name="DefaultConnection" connectionString="server = LAPTOP-U9AV480S\SQLEXPRESS2 ;AttachDbFilename=|DataDirectory|\aspnet-vidly.mdf; integrated security = true"
providerName="System.Data.SqlClient" />
the SQL server is EXPRESS and i configured the security and the login to window authentication
please help me I am stuck in this for two days

Unable to connect using sql authentication through an asp.net web app

I cannot get my web app to connect to the database when running the app. I can connect in the SQL Server object explorer and I took the connection string from the connections properties
Here is my connection string :
<add name="Quotes.DAL.QuotesConnection"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=TestDB;Integrated Security=False;User ID=sa;Password=***;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
providerName="System.Data.SqlClient" />
I can connect as SA and I can create the database that it points to in Management Studio. When my app tries to connect via Entity Framework I get the following error :
System.Data.SqlClient.SqlException (0x80131904): Login failed. The login is from an untrusted domain and cannot be used with Windows authentication. at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,
I'm running Windows 7 as a home dev machine so there is no Active Directory.
Can anybody explain why this might happen?
I have found that this is probably because I have Entity Framework in another assembly. I created a new web application and its connection string works. When it try the same connection string in my DAL it fails with this same error!
Thanks
It may be because of setting Integrated Security=False, I have never set it to false. I normally use just the bare minimum Server=myServerAddress;Database=myDataBase;User Id=myUsername;
Password=myPassword; when setting up my connection strings with sql authentication, only adding things as I need them.
The other issue I see is using SA to connect to the database. This breaks almost every best practice in the book and I would recommend creating an app specific password for when you roll out the program. The reason being is the GOD ACCESS account for the server will have its password in plain text in the app.config file. Just something to keep in mind.
EDIT: After some comment discussion the connection string was in the wrong config file.

Correct connection string MS sql server database 2008

Was hoping for a little help with my connection string to ms sql server 2008 database.
Server Type: Database Engine
Sever name: MyServer
Authentication: Windows Authentication
User Name VAW\Username
the connection string I am using at the moment is as follow
<add name="Name" connectionString="Data Source=111.111.1.1;Initial Catalog=HRElearning;MultipleActiveResultSets=True;Trusted_Connection=true;" providerName="System.Data.EntityClient" />
Error I am getting is System.Data.SqlClient.SqlException: Login failed for user 'VAW\MAWSON$'.
I to agree using VS is the better way to go, but to understand connectionstrings in general, here is the site that explains it. Once you understand exactly what is going on, freehanding them is not difficult.
The connection string you have assumes the user you are running the app with is the user you want to connect with. If you want to run app with UserA and connect with UserB then you must specify the username and password and remove "Trusted_Connection=true".

Unable to connect to SQL Server database with studio express 2012 for web

I cannot connect to SQL Server database.
When I run the aspnet_regsql.exe utility, I get the following error message:
Setup failed.
Exception:
Unable to connect to SQL Server database.
Details of failure
System.Web.HttpException: Unable to connect to SQL Server database. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred 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)
Also, I am unable to use the ASP.NET Website Administration Tool. When I click on the Security tab I receive the following error:
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
So, I click on the 'Choose Data Store' button as instructed, which allows me to select a a Provider. The provider is named 'AspNetSqlProvider', it has a Test link beside it. I click on Test and receive the following error message:
Could not establish a connection to the database.
If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.
I have lost overtime for this problem, but i cannot fix it. I hope everybody can help me.
I look forward receive the good answer as soon as possible. Sincerely thanking you very much for your help.
I encounter the same problem in my ASP.NET MVC project as you, when using the ASP.NET Website Administration Tool. The solution is to check and modify your web.config file. I just change the following attributes (add a field):
1) from
<profile>
<providers>...</providers>
to
<profile defaultProvider="DefaultProfileProvider">
<providers>...</providers>
2) from
<membership>
<providers>...</providers>
to
<membership defaultProvider="DefaultMembershipProvider">
<providers>...</providers>
3) from
<roleManager>
<providers>...</providers>
to
<roleManager defaultProvider="DefaultRoleProvider">
<providers>...</providers>
And, be sure to have something like:
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-MvcApplication1-20160111151822;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-MvcApplication1-20160111151822.mdf" />
</connectionStrings>
and the "DefaultConnection" has a corresponding field connectionStringName="DefaultConnection" under <profile>,<memebership>and <roleManager> tags, which are modified as stated above.
If you still have problems in your MVC project, just create a new full ASP.NET MVC Web Application template, compare the web.config file with yours, and modify your web.config file.

asp.net editing the "connectionstrings.config " problem

Thanks in advance.
I am attempting to edit the connectionstrings.config to connect to my sql server (locally) but it does not success.
The error message shown when i test in visual studio is:
Login failed for user 'TAT-PC\TAT'. The user is not associated with a trusted SQL Server connection
The content now in connectionstrings.config is:
<add name="NopSqlConnection" connectionString="Data Source=TAT-PC\SQLEXPRESS;Initial Catalog=hand;Integrated Security=False;Persist Security Info=False;User ID=TAT-PC\TAT;Password=;Connect Timeout=30"/>
The server is build by sql server 2005. And when i use the management tool to access
the config are:
Server type:Database Engine Server
Name:TAT-PC\SQLEXPRESS
Authentic: Windows Authentic
User Name:TAT-PC\TAT <===Which is Not editable
Password: <==no password
So, my question is how to edit the connectionstrings.config in order to connect to the server??(I have already create the schema "hand")
Have you assigned permission to your local user to sepcific database on sql server ? No need to mention any username or password. Just use trusted connection string.

Resources