'"The system cannot find the file specified" error trying to connect to database

I have an application hosted in a server. Database is being uploaded to the server also. When I try to run the website this error showed up:

The system cannot find the file specified

After some research I came to know that this error might be related to the instance name or the database is not accessible. But when I try from my local host with Visual Studio with the same database connection string it runs perfectly.

What can be the possible reason for this strange behavior?

I am developing a SASS application. The database connection string is chosen dynamically according to the appSettings in web.config file. Is this can be the issue?

Code Sample:

<appSettings>
   <add key="myDomainName" value="myDomainName" />
   <add key="localhost:1234" value="MyConnectionString" />
</appSettings>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source