Internet Application - authentication

A default ASP.NET MVC 4 project with an account controller that uses forms authentication, but this authentication give this error on IIS 7.5 on my server.
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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)
How can I solve this as I cant find any connections on class.

The default MVC 4 project relies on IIS Express and LocalDB, the LocalDB generated is stored in the App_Data folder.
However when changing the project to run under full IIS you are advised to switch to using SQL Express. For this you will need to create a database and set up the relevant connection string. Assuming your application has the relevant permissions and the WebSecurity.InitializeDatabaseConnection has autoCreateTables set to true the relevant tables will automatically be created.
The default database initialization is done via the InitializeSimpleMembershipAttribute we can be found in Filters/InitializeSimpleMembershipAttribute.cs this attribute is then applied to the AccountController.

You should check Windows log as suggested in exception message. Connection string is in the web.config file of your web application.

Related

Problem with update-database on Visual Studio 2022 ASP.NET Core MVC

I am getting this error and I really don't know what to do:
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: SNI_PN11, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)
I am using VS 2022 with .NET 6.0 version for my ASP.NET Core MVC web application project.
Whenever I am using update-database after add-migration I am getting this error.
Please check your configuration for db connection. It seems a db is configured where youd dont have access or a database which is remote but does not exist.
Mostly you find the connection in local.settings file.

SQL Server 2005 - The Local Security Authority cannot be contacted

I'm suddenly having a problem connecting to my local instance of SQL Server 2005 Database engine. I had no problem connecting to this instance a few days ago. I can however connect to Integration Services and Analysis Services. Only the Database engine is giving me this error:
A connection was successfully established with the server,
but then an error occurred during the pre-login handshake.
(provider: SSL Provider, error: 0 -
The Local Security Authority cannot be contacted) (Microsoft SQL Server)
Only thing I did was I installed Visual Studio 2017.
This is a generic error that has many reasons. Usually is things like expired password. To troubleshoot, you should enable Netlogon service logging, follow Enabling debug logging for the Netlogon service:
c:\>Nltest /DBFlag:2080FFFF
Then reproduce your problem then look into the logging file, which is going to be located at %windir%\debug\netlogon.log. Read the file, try to understand what is happening.
Don't forget to turn off the debug logging afterwards:
c:\>Nltest /DBFlag:0

Visual Studio 2015 connection to MS SQL 2008 Server

I've built an application in vb.net with Visual Studio 2015 which I need to update now. I need to update the Table Adapter through Dataset Designer but when I click Configure on the Query I get the error:
Failed to open a connection to the database
"The client was unable to establish a connection because of an error
during connection initialization process before login.
Possible causes include the following: the client tried to connect to
an unsupported version of SQL Server; the server was too busy to
accept new connections; or there was a resource limitation
(insufficient memory or maximum allowed connections) on the server.
(provider: Named Pipes Provider, error: 0 - No process is on the other
end of the pipe.)"
Check the connection and try again.
Previously this worked just fine. The application still works fine and connects to the MS SQL server using the same connection string. I'm using the .NET Framework Data provider for SQL Server. See images.
Dataset Designer -> Configure / Edit Query
Error message after I click on Configure + Connection String
It's important to note that the application connects using the same Connection String and everything worked fine previously.
SOLVED! Figured out the problem. The "Named Pipes" setting in the SQL configuration was disabled. First I tried to access the server via IP address and succeded. Then I checked under SQL Server Configuration Manager -> SQL Server Network Configuration -> Protocols for -> Named Pipes and it was Disabled. I've set it to Enabled. I have no idea why it switched do Disabled, it was not like this before.

The server was not found or was not accessible - Server was lost for 6 hours

First off, I only have a very basic understanding of SQL. I can create tables etc. but configuration is beyond me. I am running my web site with MVC3 ASP.Net on a windows 2008 server using SQL Express.
Everything works fine, my connection strings are correct, I can use the website and it reads and writes to the dB, I can also view the dB with management studio on the server.
Today I got 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)
When I tried to log on to the database in management studio on the server I get a similar error. the only fix I have found is for a server restart. The database was down for 6 hours before I noticed which is not good for a start up website.
Has any one seen this issue before? Is this an express issue? Any help or advice would be great.
Troubleshoot as you would any network error. Start with the server's event logs.
As for notification of downtime, there are a lot of web services that will monitor your web site and email or send you an SMS message if it's not responding. Two that I've used are uptimerobot.com and basicstate.com. There are dozens of others.
You could also rewrite your ASP.Net app to email or text you when certain kinds of errors happen.

Entity Exception : the underlying provider failed to open with Timeout expired

OK, I'm stumped. I am trying to create a .NET Winforms app to talk to a database via Entity Framework. I originally created a ASP.NET MVC3 app (with a seperate DAL layer) that can talk to the database after initially failing. SO the first time that it tries to open the connection, it times out. If I then hit F5 in the browser, it connects fine!
I referenced this DAL in my Winforms app.
I can connect to the database via SQL Auth in SQL Management Studio fine.
I can create the ADO.NET Data classes in VS2010 (it connects, gets the tables and stores the connection string in the app.config).
However, once I run the Winforms app, I am unable to connect. I get the mentioned exception with an InnerException of "Timeout expired."
I copied the connection string from the web.config to the app.config.
The SQL database is hosted on my Windows Home Server called SERVER. I am in a Workgroup (no Domain). I uses SERVER\SQLEXPRESS in Management Studio and VS to successfully connect to it.
Things I've tried:
Disable the firewall on the client machine.
Enabled DTC on the server and added msdtc.exe to the exclusion list on the server.
Made sure Named Pipes in enabled on the SQL server instance.
Tried different SQL users.
Tried different ways of constructing the connection in C#.
Generated a new ADO.NET Data class local to my WinForms project (not referencing the DAL). VS connects fine, reads the tables, generates the code. But the running app causes a "Timeout Expired" SqlException.
So running the app is unsuccessful in connecting. When I watch the app in ProcessExplorer I can see an entry in the TCP window when it tries to Connect on remote port 4845 with a SYN_SENT message. Not sure if that's right.
I've google'd and bing'd this for the last few days, I've read all the articles and replies here on Stackoverflow that mention this exception, but I have hit a wall.
This is the ConnectionString that VS generated after reading the DB:
<add name="LLDBEntities" connectionString="metadata=res://*/LLDB.csdl|res://*/LLDB.ssdl|res://*/LLDB.msl;provider=System.Data.SqlClient;provider connection string="data source=SERVER\SQLEXPRESS;initial catalog=LLDB;persist security info=True;user id=sa;password=sapwd;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Any help appreciated, even any hints on how to figure out what's happening.
Your connection string looks more like a connection string to an SQL Server, rather than SQL Express.
Have a look at this for a connection string to SQL Express: SQL Server Express connection string for Entity Framework Code First
Ok, solved.
I noticed that it would actually connect on the second attempt with the same app and connection. At that point I found this link: http://kromey.us/2011/06/microsoft-sql-server-2008-times-out-on-first-connection-attempt-447.html
So I opened the firewall port listed under IPAll Dynamic Port in SQL Server Configuration Manager on the TCP/IP Properties for the instance and now it all works fine. I still don't know why it would get through on the second attempt....