Validating the user role in a view asp mvc 5 - c#

I am conducting a validation role in this line of view
#if (User.IsInRole("Admin"){}
or
#if (Role.IsUserInRole("Admin"){}
When I run it locally it works fine, but on the web this generates the following error:
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)
I connect the database from my local server and it does not generate an error
I could give a hand, thanks

Related

Occasional Exceptions: "A network-related or instance-specific error occurred while establishing a connection to SQL Server"

Occasionally our web application throws:
System.Data.SqlClient.SqlException (0x80131904): 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) ---> System.ComponentModel.Win32Exception (0x80004005): The network path was not found
Now I have Googled maybe all kinds of variations regarding this error but all seem to point to the fact that the destination SQL server is either down or doesn't accept remote connections or something wrong with the connection string.
But my scenario is different, I can definitely reach the SQL Server (separate machine, same LAN) and this application runs normally most of the time, but in certain instances it starts to generate these errors. Then, apparently, they stop on their own then randomly they start again. Other applications on the same server to the same SQL Server (though different databases) throw these errors as well during the same period.
I have left a continuous ping between the two servers and I can confirm that during this period both servers have IP connectivity between them.
What could be the cause of this problem? What can I check next?
Did you make sure that TCP/IP is enabled under Sql Server Configuration management->SQL Server network config->protocols ?

Connection String related error

I'm using Windows authentication for SQL Server in my project and the error I receive while saving the data is:
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)
My connection string is:
Server=LOKESH; Initial Catalog=test; Integrated Security=SSPI

Reading content from MS Access db using ADO.net and trying to insert the values into a SQL Server table

I'm using an OleDb connection to read a table in MS Access. I've closed the connection and I'm trying to insert the values retrieved into a SQL Server table using Entity Framework.
While establishing the connection to SQL Server, I'm getting an error:
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)
The error message is crystal clear: the server was not found. So, take this two steps.
Verify your connection string for misspelled server name.
Verify your SQL Server instance is accepting connections from network, what is disable by default.
Go to:
Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
Click on Surface Area Configuration for Services and Connections
Select the instance that is having a problem > Database Engine > Remote Connections
Enable local and remote connections
Restart instance
See this article:
http://www.sswug.org/articlesection/default.aspx?TargetID=44331

error in connect to sqlserver in windows and sql authentication mode

i have a snippet that it work properly when i use windowsmode with follow connection string
data source=.;database=xDB;integrated security=true;
but i have to change it for sql and windows mode i changeit to
Data Source=.;Initial Catalog=xDB;User Id=krs;Password=12345;
but follow error occur
Login failed for user 'krs'. The user is not associated with a trusted SQL Server connection.
and when change dot(.) to(local) another error occur
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)
plz help me im beginer n confused.thank
You have to enable the Named Pipe & TCP/IP in SQL Server configuration. Go through following link to enable that
http://www.triostechs.com/Microsoft-SQL-Server-2008/Microsoft-SQL-Server-2008-Enable-TCP/IP-or-Named-Pipes.html
Also Make sure, only one instance of the SQL Server running. If it is more than one, just verify which one you are connecting to.

How to give database access to a program?

I created an MVC application that accesses my SQL Server database using LinqToSql. But I get an exception on dbGuestbookContext.SubmitChanges();
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 can access other databases on that server from other applications.
Could you please tell what I can do about this?
Thaks.

Categories

Resources