如何使用 WebMatrix 连接到 SQL Server 数据库?

2021-09-23 00:00:00 sql-server 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");

抛出异常:未找到连接字符串MyNewConnection".

推荐答案

您是否检查过 web.config 文件中的连接字符串是否正确?

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>

相关文章