Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i have hosted my project on the aws and its working good,but when im inserting some data that time it will showing some connection error. it is failing to connect to the database.

while im inserting im getting below 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 erron is on line no:54

Line 52: cmd.Parameters.AddWithValue("@hint", txthint.Text.Trim());
Line 53: cmd.Connection = con;
Line 54: con.Open();
Line 55: userid = Convert.ToInt32(cmd.ExecuteScalar());
Line 56: con.Close();

What I have tried:

i have tried each and every solution given in google and youtube to fix this issue but my issue is remains same and it not solved yet.
Posted
Updated 7-Apr-16 3:45am
v2

1 solution

Use the debugger, and look at exactly what is in the connection string to set up con to use - and then check that from your PC to make sure it's good.
We can't do that for you - we don't have access to your DB server, or even any idea where you load the connection string from!
If you can't use a debugger on the actual machine running that code, then add logging statements to save the data to a file, and look at it after the error has occurred.
The chances are that you are specifying the wrong server, or a server that the machine you execute the code on can't reach.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900