views:

169

answers:

2

I got a problem. When i'm creating the new project in ASP.NET using VS 2010, it's web.config with a default connection string about SQL Express created. But i haven't even got SQL Express installed. What should i do to change the default AspNetSqlProvider to work with my instance of full-weight SQL Server as a services database? And how can i change the template for the ASP.NET project to create a project with my connection?

+3  A: 

You mean this one:
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />

To change this into one that'll work with SQL Server, it needs to look more like this:
<add name="ApplicationServices" connectionString="data source=ServerName;Initial Catalog=DatabaseName" providerName="System.Data.SqlClient" />
where DatabaseName is probably aspnetdb. It'll need some form of authentication, whether you use Windows authentication (in which case you can copy the Integrated Security element from the original connection string) or SQL Server authentication (where you'll have a username/password combination).
There's great info on building connection strings at connectionstrings.com.

To fix this for your future projects, you'll need to change the template for Web Projects. Locate the folder where your C# Web templates are kept (for me this is C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\Web\1033.
Take a copy of the WebApplicationProject40.zip file (you might also want to backup the original somewhere!). Inside it you'll find the web.config file with the SQL Express connection string. Change it to a SQL Server string, and then re-assemble the zip file.
The last step is to rebuild the VS template cache - from a command-line (VS Command Prompt probably works best), run devenv /installvstemplates. See here for details.

PhilPursglove
Thanks a bunch for saving the time i would dig for this information over the internet.It works perfectly.
Proton
connectionstrings.com is always REALLY useful !
Julien N
A: 

I just had a similar problem. I had a web site created in VS 2008 and wanted to try web parts. Added some to a page, then started getting:

SQLExpress database file auto-creation error:

The connection string specifies a local Sql Server Express instance using a database >location within the applications App_Data directory.

I ran aspnet_regsql.exe (wizard, in .Net framework folder) to create the database and then I added a connection string to web.config:

<configuration>
    <connectionStrings>
        <add name="aspnet_membership" connectionString="Data Source=localhost; Initial Catalog=aspnetdb; Integrated Security=SSPI;"/>
    </connectionStrings>
</configuration>

Then I added this to web.config:

<configuration>
  <system.web>
    <webParts>
      <personalization defaultProvider="SqlPersonalizationProvider">
        <providers>
          <add name="SqlPersonalizationProvider"
          type="System.Web.UI.WebControls.WebParts.SqlPersonalizationProvider"
          connectionStringName="aspnet_membership"
          applicationName="/" />
        </providers>
        <authorization>
          <deny users="*" verbs="enterSharedScope" />
          <allow users="*" verbs="modifyState" />
        </authorization>
      </personalization>
    </webParts>
  </system.web>
</configuration>
robaker