0

I added a new Sql Server Database to my project with the name: ShDB.mdf. It is located in a App_Data folder.

It contains a Table which has some columns. I could add some numbers to the table and then show them in a gridview on my localhost. This is what I have in the web.config:

`<configuration>
  <connectionStrings>
    <add name="ShConnectionStr" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Javad\Desktop\Sharj\App_Data\ShDB.mdf;Integrated Security=True;User Instance=True"/>
    <add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ShDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
    <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
    </system.web>

`

Here is the vb.net code which I used:

Dim connectionString As String = ConfigurationManager.ConnectionStrings("ShConnectionStr").ConnectionString

And it works properly on the localhost test but when I published the website and uploaded the files on a web hosting service to test, I counter an error. How may I fix it? I think I should change my Data source path but I don't know how because its my first experience. Thanks to any help. you can see the error page here: http://www.kaj.somee.com/SL.aspx

4
  • Is Sql Express installed on the server? Commented May 21, 2014 at 13:49
  • I don't Know. what should I do if it is not installed? Commented May 21, 2014 at 13:54
  • Can download and install it, the installer is here: microsoft.com/en-us/download/details.aspx?id=29062 Commented May 21, 2014 at 13:57
  • If the Sql Express has been installed on the server then isn't it necessary to change the C:\Users\Javad\Desktop\Sharj\... ? I know this path is located in my PC. I am new with it. thanks for your help. Commented May 21, 2014 at 13:59

2 Answers 2

1

Sql Server is either not installed or not running on the web host, or you don't have access to connect to it.

ASP.Net does not by itself know how to use your *.mdf database. It needs a running instance of Sql Server to talk to. It will tell Sql Server to load (attach) your database file, and then send queries to the Sql Server service for execution.

Sign up to request clarification or add additional context in comments.

Comments

0

Do you mean you already uploaded the website to a web hosting service, but not the database? If so, your application may not communicate directly with your database which is actually in your local machine. You probably need to upload the database to a database hosting service as well (eg.SQL Azure, etc). You may need to figure out the IP address/Server Name of your database hosting where you have uploaded. These information you can probably get in for the service provider. From there you should be able to connect to the database with the correct configuration.

1 Comment

I also uploaded the ShDB.mdf to the web hosting service like every files which I uploaded. But I don't know how to use it and it really bothers me.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.