![](/img/trans.png)
[英]How to connect to SQL Server database and retrieve data using Razor in WebMatrix?
[英]How do I connect to a SQL Server database using WebMatrix?
我添加了一個連接,它顯示在“其他連接”中,但我似乎無法引用它。
var db = Database.Open("MyNewConnection");
拋出異常: Connection string 'MyNewConnection' was not found.
您是否檢查過以確保您的web.config文件中的連接字符串是否正確?
<?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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.