简体   繁体   中英

How do I connect to a SQL Server database using WebMatrix?

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM