0

I am newbie and confused how to do it.

I have built MVC 3 application in Visual Studio 2010 and published to the localhost and it's working fine.

Here, What I actually want is to use the Sql Server 2008 installed in my computer rather than database under the folder APP_DATA that I have created using visual studio.

I am new to the MVC and don't know about the database connection detailly. Following is the connection string of the web.config file:

 <connectionStrings>
   <add name="IVRControlPanelEntities" connectionString="metadata=res://*/Models.IVRControlPanelModel.csdl|res://*/Models.IVRControlPanelModel.ssdl|res://*/Models.IVRControlPanelModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\IVRControlPanelDB.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

This is the connectionstring automatically added by the visual studio while adding the data entity model.

After published to localhost the database used by mvc 3 is under the APP_DATA folder of wwwroot folder.

What I need to change to connect to the Sql Server 2008 installed in my computer rather than database created on the Visual Studio.

One more thing, I could not import the database created by visual studio to the sql server 2008 which is in the form IVRControlPanelDB.mdf

Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281
CodeManiac
  • 974
  • 8
  • 34
  • 56
  • You can't import mdf files directly. You can create a database and attach a mdf file then. – YvesR Aug 22 '12 at 06:28

2 Answers2

0

You should use Database.SetInitializer<> method in Application_Start method in Global.asax

read this and this ,this article may help too.

Community
  • 1
  • 1
Vahid Hassani
  • 676
  • 1
  • 6
  • 20
0

You need to modify your connectionstring to add the address to your sql server. Example:

  <connectionStrings>
    <add name="ApplicationServices"
         connectionString="Server=localhost;Database=myDatabase;User Id=myUser;Password=myPassword;"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
Mickle Foretic
  • 1,399
  • 12
  • 23