views:

37

answers:

1

I added a connection and it shows up in "Other Connections" but I can't seem to reference it.

var db = Database.Open("MyNewConnection");

throws an exception: Connection string 'MyNewConnection' was not found.

+1  A: 

Have you checked to make sure your connection string is correct in your web.config file?

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
   <add 
     name="MyNewConnection" 
     connectionString= "server=myServer;database=myDatabase;uid=username;pwd=password"
     providerName="System.Data.SqlClient" /> 

  </connectionStrings>
</configuration>
Joe Stefanelli
Oddly, I don't see that it created a web.config file. In fact, I don't see my "Other Connections" persisted anywhere.
Larsenal
I believe `Database.Open` looks for either (1) a .sdf file in the website's App_Data folder or (2) a connection string in web.config. See: [Working with Data - Connecting to a Database](http://www.asp.net/webmatrix/tutorials/5-working-with-data#SB_ConnectingToADatabase)
Joe Stefanelli