Background:
I have a Always On Availability Group Setup with 4 Nodes(DB1,DB2,DB3,DB4). I am using File Share witness hosted on some other server. All the nodes on AG are set to failover automatically. And as readable secondary option set to 'yes'.
Issue:
For instance, lets consider DB1 as primary node on both AG and WSFC. Now,whenever I stop the MSSQL service on DB1, DB2 or the other 2 becomes primary on AG. However, DB1 stays as primary host on the WSFC. The main problem here is whenever my application tries to connect to the DB, I get an error as "Failed to update 'Dbname' database is read only". But when I manually change the node of WSFC to the now Primary AG DB my application starts working. Can someone please help me out here.
whenever my application tries to connect to the DB, I get an error as "Failed to update 'Dbname' database is read only"
Your app needs to connect to the AG through the AG Listener, which will only be active on the node hosting the primary database replica.
If your app is connecting to the listener you need to troubleshoot the connection. Verify that DNS resolution is returning all the IP addresses, and that only the IP address hosting the primary replica has the requested SQL Server port open.