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

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

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

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:

"Network Path was not found" SQl Exception (0x80131904) .. Named pipe provider error 40 could not open connection with SQL server

I developed an asp project on my local computer and everything worked perfectly until I wanted to move the project to a server (Windows Server 2012)
Simple Asp.net pages run flawless but once I try to connect to out SQL Server we get the error
"Network Path was not found"
SQl Exception (0x80131904) .. Named pipe provider error 40 could not open connection with SQL server
My connection string is defined in the web config file
<connectionStrings>
<add name="conString" connectionString="Data Source=WIN-XXXXXXXXXXX; Initial Catalog=YYY; Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
A simple test asp pages which uses a SqlDataSource and a Gridview works fine!
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("conString").ConnectionString
But when I try to use my Sql Connection in the code behind I get an error. It can not be the connection String as it is exactly the same used in the SqlDataSource Object earlier.
connection = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("conString").ConnectionString)
connection.open()
+some SQL
throws the error.
Note: This is the first time I am trying to set up a server myself, and after hours of trying things out I don't know what to do anymore.
Enable TCP/IP,Named Pipes In sql server configuration manager.Expand Sql Native client 11.0 Configuration manager. In client protocols you will see TCP/IP, named Pipes,Via disabled, enable those,Expand Server Network Configuration In Protocols for Sql Server here Enable Shared,Named,TCP/IP,Expand Sql Native client 11.0 Configuration manager. and restart the services For more info Refer this Link Named Pipes Error 40

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.

Cannot connect to mysql database in .NET MVC3

I've having some trouble in connecting mvc 3 application in .net. I know that mysql database instance has to be created before using web.config file to connect the it. My
connectionStrings as below:
<connectionStrings>
<add name="epmsDb"
connectionString="Server=localhost;Database=database1;
Uid=root;Pwd=mypassword"
providerName="System.Data.SqlClient" />
</connectionStrings>
and I've got a database name call epmsDb created in Server explorer. Then I tried to get the connectionString in the code using this :
string connectionString =
ConfigurationManager.ConnectionStrings["epmsDb"].ConnectionString;
context = new DataContext(connectionString);
usersTable = context.GetTable<UserObj>();
Every time I tried to access the database, I threw this exception:
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)
I've been trying to overcome this for a week now. Does anyone have ideas why this occurres?
Your example tries to connect to an MS SQL database. To connect to a MySQL DB you might want to use the MySQL connector
Then change the ProviderName property:
<connectionStrings>
<add name="epmsDb"
connectionString="Server=localhost;Database=database1;
Uid=root;Pwd=mypassword"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>

Resources