cant log in to the database file on visual studio asp.net - 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

Related

Error about ASP.NET security configuration(cannot connect to sql )

I've installed SQL Server 2012 and visual studio express for web 2012, I found that I couldn't connect to SQL via asp.net. I installed another SQL Server 2012 instance and changed datasource to (LocalDB)/v11.0, it then works.
But in the security configuration, though I've set the windows authentification,I get this error:
There was a problem with the selected datastore, which could be due to an invalid server name or credentials, or insufficient permissions. It may also be caused by the role manager feature not being enabled. Click the button below to redirect to a page where you can select a new data store.
The following messages may help diagnose the problem: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or cannot be reached. Verify that the instance name is correct and SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26-An error occurred while locating the specified server / instance)”
After testing the provider for storing site management data:Aspnetsqlprovide ’connection with sql,another error happens:
Failed to establish database connection.
If you haven't created a SQL Server database, exit the site administration tool, use the aspnet_regsql command-line utility to create and configure the database, then return to this tool to set up the provider.
Following the error message, I installed aspnetdb to this (LocalDB)/v11.0, and changed the codes in machine.config:
<connectionStrings>
<add name="LocalSqlServer"
connectionString="Data Source=(LocalDB)\v11.0;Initial Catalog=aspnetdb;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
I also set IIS connection strings as codes above and changed Application pool identity to“LocalSystem”,but these errors still occurs.
I really hope someone can help me to handle this, thanks

ASP.NET MVC network-related or instance-specific error

I am getting this error
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: SQL Network Interfaces, error: 26
- Error Locating Server/Instance Specified)'
When I try to run my ASP.NET MVC project. Opening it for the first time on this PC.(I try to register a user and the database doesn't get created and I get the error above.) The database should get created the first time I hit the database PS: It's a code first project
I thought I know how to fix it until now.
The project runs on my other PC but on this not.
So I thought I'll go and change the connection string to
<connectionStrings>
<add name="foo"
providerName="System.Data.EntityClient"
connectionString="Data Source=localhost"/>
</connectionStrings>
(just change the Data Source= to localhost)
The constructor in my DbContext is
public EventManagerDbContext() : base("foo")
{
}
Still I can't run my project.
PS: I am able to connect to my database using the SQL Server Management Studio, but not from the project. Why is that?
I realised that the problem was that my connection string was placed in the Data Access Layer. But it has to be in the ASP.NET MVC application right? Would like some clarification.
Provide a complete details to your connectionstring like this:
<add name="foo" connectionString="Data Source=.\SQLEXPRESS2014;Initial Catalog=NameOfYourDB;
Integrated Security=True;"
providerName="System.Data.SqlClient" />
I suppose that your localhost is .\SQLEXPRESS2014 is your local machine server name.
To get the full server name on your part, connect to server, under Server Name, choose Browse for more option, then select Network Servers tab, and it will list your qualified server name:

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

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)

How to set a proper connection string for Azure database?

I have an azure website and database. I'm running an ASP.NET MVC 4 / EF 5 app localy and trying to put some data to the azure database before to deploy the app. But I have a TargetInvocationException : {"The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588"}
Keyword not supported : server
This is the connection string that I get from my azure dashboard :
<add name="myconstring" connectionString=Server=tcp:myserver.database.windows.net,1433;Database=mydatabase;User ID=cdptest#myserver;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient" />
I tried this I got "Keyword not supported : data source"
<add name="myconstring" connectionString="Data Source=myserver.database.windows.net;Initilal Catalog=mydatabase;User ID=cdptest#myserver;Password=*****;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient"/>
The following works for me:
<add name="coupdpoAPEkowswAEntities" connectionString="Server=tcp:myserver.database.windows.net,1433;Database=mydatabase;User ID=cdptest#myserver;Password=*****;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;" providerName="System.Data.EntityClient"/>
Use Server instead of Data Source, and specify the protocol and the port, and use Database instead of Initial Catalog
OK the providername was wrong. System.Data.SqlClient was excepted as this is a code first app model.
I probably got System.Data.EntityClient from another app with Model First or Database First...

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.

Resources