How to connect to SQL Server database using WebMatrix?

I added a connection and it appears in the "Other Connections" section, but I can’t link to it.

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

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

+4
source share
1 answer

Have you checked to make sure your connection string is correct in the 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> 
+6
source

All Articles