0

I have developed a website in asp.net and upload onto a server. But I unable to connect to my SQL Server database (on localhost, I am able to run but not on the server)

I am using following code.

con = new SqlConnection("server=**********,****\\sqlexpress;Database=******;User ID=******;Password=*********");
con.Open(); 

but I'm unable to open the connection.

I am getting this error related to web.config:

<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>

Notes: The current error page you are seeing can be replaced by a custom error page by modifying the defaultRedirect attribute of the application's <customErrors> configuration tag to point to a custom error page URL.

<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>

So please help me how can resolve it

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Where is the database in server machine or somewhere else ? – Raghubar Dec 14 '13 at 07:44
  • database is in server machine – user3101714 Dec 14 '13 at 08:08
  • I think there is problem in instance name. You can use (local) as sever or use lan IP of that machine. – Raghubar Dec 14 '13 at 08:44
  • 1
    I would guess that the **server**'s database instance probably isn't called `.\SQLEXPRESS`. Most likely, it's either a default instance without a name, so try `.` or `(local)` or `ServerName` as your server name, or then it's some other instance name that you should know or inquire about with the server's hosting service. – marc_s Dec 14 '13 at 09:45
  • Yes, I agree, the server name is not correct. Please kindly check it again. If you use hosting provider, please ask them about the correct connection string. –  Dec 15 '13 at 01:02

2 Answers2

0

Use the following Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;

Check the instance name of the remote server. Check if you can connect in sql management studio and use the same credentials in your app.

Juan
  • 1,352
  • 13
  • 20
0

I've answered two similar questions on SO, first try creating a .UDL file and test your connection from there. You can then copy and paste the connection string. You may need to remove the Provider property though.

See this question and this one for a full description.

Community
  • 1
  • 1
Damon
  • 3,004
  • 7
  • 24
  • 28