Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
    
Is Sql Express installed on the server? –  mxmissile 19 hours ago
    
I don't Know. what should I do if it is not installed? –  user3637733 19 hours ago
    
Then install it –  DNKROZ 19 hours ago
    
Can download and install it, the installer is here: microsoft.com/en-us/download/details.aspx?id=29062 –  mxmissile 19 hours ago
    
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. –  user3637733 19 hours ago
add comment

2 Answers

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.

share|improve this answer
    
That would be SQL Server Express right? o_- –  Neil Hibbert 19 hours ago
    
That is one edition of Sql Server, yes. –  Joel Coehoorn 19 hours ago
add comment

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.

share|improve this answer
    
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. –  user3637733 19 hours ago
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.