asp.net中的sqldependency [英] sqldependency in asp.net
问题描述
你好
我遇到了一些代码。我现在正在返回SQL数据库(请注意 - 没有SQL SERVER MANAGEMENT STUDIO)内置到MDF文件中VISUAL STUDIO代码如下所示:
Hello
I got stuck in some code. I'm working now on the return of the SQL database (note that - no SQL SERVER MANAGEMENT STUDIO) built into the MDF file VISUAL STUDIO The code looks like this:
using (SqlCommand cmd = new SqlCommand(query, MyConnection))
{
cmd.Notification = null;
DataTable dt = new DataTable();
SqlDependency dependency = new SqlDependency(cmd);
if (MyConnection.State == ConnectionState.Closed)
MyConnection.Open();
var rdr = cmd.ExecuteReader();
dt.Load(rdr);
if (dt.Rows.Count > 0)
{
name = dt.Rows[0]["ProdName"].ToString();
price = int.Parse(dt.Rows[0]["Price"].ToString());
image = dt.Rows[0]["Images"].ToString();
}
dependency.OnChange += new OnChangeEventHandler
(dependency_OnChange);
..........
但由于某些原因它不起作用,在我看来是一个错误,上面写着:
存在同名的数据库,或指定的文件无法打开,或者它位于UNC共享上
我也是更新文件WEB.CONFIG
缓存
sqlCacheDependency pollTime =500enabled =true
add name =DataprodconnectionStringName =ConnectionString
数据库
sqlCacheDependency
缓存
........
它不起作用
谢谢
..........
But for some reason it does not work and appears to me an error that says:
"A database with the same name exists, or specified file cannot be opened, or it is located on UNC share"
I also updated the file WEB.CONFIG
caching
sqlCacheDependency pollTime="500" enabled="true"
add name="Dataprod" connectionStringName="ConnectionString"
databases
sqlCacheDependency
caching
........
And it does not work
Thanks
推荐答案
错误,存在同名的数据库... ,表明您的连接字符串存在问题。
最有可能的是,您已指定AttachDbFileName
,但忘记指定用户实例= TRUE;
。因此,SQL已将您的MDF文件作为常规数据库附加;当它第二次尝试附加它时,数据库已经存在,并且你得到这个错误。
要解决问题,请手动分离现有数据库,然后添加您的连接字符串缺少设置。
The error, "A database with the same name exists ...", suggests that there's a problem with your connection string.
Most likely, you've specifiedAttachDbFileName
, but forgotten to specifyUser Instance=true;
. As a result, SQL has attached your MDF file as a regular database; when it tries to attach it a second time, the database already exists, and you get this error.
To solve the problem, manually detach the existing database, and add the missing setting to your connection string.
这篇关于asp.net中的sqldependency的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!