user2416905
user2416905

Reputation: 31

The connection string for a local SQL 2012 Express Server Instance

So I've been wanting to learn a little more about SQL but I'm having some trouble connecting to a local SQL server database in the ASP.NET project I'm working on. Though I'm able to connect using Visual Studio and SQL Server Management Studio, I just can't get the connection string right. I've been looking at connectionstrings.com but I get exceptions when using alot of the keywords it suggests (server, initial catalog, database, etc.).

*Edit - Added Web.config

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
  </system.web>

  <connectionStrings>
    <add name="StarterSite" connectionString="Data Source=|DataDirectory|\StarterSite.sdf" providerName="System.Data.SqlServerCe.4.0" />
    <add name="AdventureWorks" connectionString="Data Source=ROBERT-PC;Initial Catalog=AdventureWorks2012;Integrated Security=True" />
    <add name="DefaultConnnection" connectionString="Data Source=ROBERT-PC\MSSQLSERVER;Initial Catalog=AdventureWorks2012;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD"
  providerName="System.Data.SqlClient" />
    </connectionStrings>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
        <bindingRedirect oldVersion="1.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234.0.0" newVersion="1.5.2.14234.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
<system.data>        
        <DbProviderFactories>
            <remove invariant="System.Data.SqlServerCe.4.0" />
            <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
        </DbProviderFactories>
    </system.data></configuration>

Upvotes: 1

Views: 1423

Answers (1)

makemoney2010
makemoney2010

Reputation: 1242

Generally visual studio per default use "defaultConnectionString" you may try this

<add name="DefaultConnnection"
  connectionString="Data Source=YOURMACHINE\YOUR_SQLEXPRESS_INSTANCE;Initial Catalog=DATABASE_NAME;Persist Security Info=True;User ID=USERNAME;Password=PASSWORD"
  providerName="System.Data.SqlClient" />

Obviously it will change if you are using EF it could be little bit different

Upvotes: 2

Related Questions