SharePoint Web 部件 - SQL 语句未反映更改
我最近用 C# 编写了一个 SharePoint Web 部件,它使用基于用户选择的一些参数化查询从 SQL 数据库中提取信息。这涉及下拉列表中的客户列表,该列表是从数据读取器填充的,如下所示:
while (dr.Read())
{
string customerNameAndCity = dr.GetSqlString(1).Value + " - " +
dr.GetSqlString(2).Value;
customers.Items.Add(new ListItem(customerNameAndCity, dr.GetSqlString(0).ToString()));
}
基本上,这会读取每个客户的姓名和城市,并将输出连接到一个字符串中,该字符串将添加到下拉列表的 Items 集合中(称为“客户”) ”)。它使用的 SQL 命令是:
SELECT fldCustomer_ID, fldCustomerName, fldCity
FROM dbo.tblCustomers
WHERE fldActive = 'True'
ORDER BY fldCustomerName
显然,有一个名为“fldActive”的列,当该字段设置为“True”时,它允许这段代码将该客户添加到该下拉列表中。
到目前为止我还没有遇到任何问题。然而,今天早上,我将一个测试客户的 fldActive 列设置为“True”,以便测试一些新的存储过程,并尝试查看该客户的信息。运气不好。客户的信息未呈现在我的下拉列表中。然后我执行 iisreset 并重置数据库 (SQL Server 2005)。还是没有运气。因此,我打开了源代码并逐步完成了填充此下拉列表的方法。当我单步执行时,我可以看到测试客户的数据实际上已加载,文本已连接,并且 Items.Add 毫无例外地完成。循环完成后,我检查了客户下拉列表,实际上该条目就在那里。然而,一旦页面加载,我遇到了同样的问题:所有条目都出现了;测试客户根本不在那儿。没有空的条目或任何东西;就好像这里从未有人居住过一样。
我唯一能想到的是某处正在进行一些缓存,但我只是不知道为什么会发生这种情况。我还清除了 IE 缓存,并且我认为在清除 IE 缓存和 iisreset 以及数据库重新启动之间,我会被覆盖。预先感谢您可以提供的任何帮助。
编辑:我刚刚重新启动了完整的服务器,现在信息正确显示。显然,需要重新启动单个组件才能正确显示。有谁知道那可能是什么?显然不是数据库或IIS的问题,我不想每次数据改变时都必须重新启动整个服务器。
编辑:我刚刚又遇到了这个问题。这次,我更改了 SELECT 语句以添加一个字段,更改了 ORDER BY 语句,更新了服务器上的 Web 部件,然后运行它。 ORDER BY 受到尊重,但新字段未显示。 Sql Profiler 显示新的 SELECT 语句位于查询中,Fiddler 显示 HTTP 请求没有问题,并且我清除了 IE 缓存,但该列没有在 .aspx 页面中呈现。这一次,即使完全重新启动服务器也无济于事。
I recently wrote a SharePoint web part in C# that pulls information from a SQL database with some parameterized queries based on user selections. This involves a list of customers in a dropdownlist that is populated from a datareader like so:
while (dr.Read())
{
string customerNameAndCity = dr.GetSqlString(1).Value + " - " +
dr.GetSqlString(2).Value;
customers.Items.Add(new ListItem(customerNameAndCity, dr.GetSqlString(0).ToString()));
}
Basically, this reads the name and city of each customer and concatenates the output into a string that is added into the Items collection of the dropdownlist (called "customers"). The SQL command it uses is:
SELECT fldCustomer_ID, fldCustomerName, fldCity
FROM dbo.tblCustomers
WHERE fldActive = 'True'
ORDER BY fldCustomerName
Obviously, there is a column called "fldActive," and when this field is set to 'True', it allows this piece of code to add that customer to this dropdownlist.
I haven't had any problems with it thus far. However, this morning I set the fldActive column of a test customer that I had set up to 'True' in order to test some new stored procs and attempted to view that customer's information. No luck. The customer's information is not rendered in my dropdownlist. I then did an iisreset and reset the database (SQL Server 2005). Still no luck. So I opened up the source code and stepped through the method that populates this dropdownlist. When I step through it, I can see that the test customer's data is, in fact, loaded, the text is concatenated, and the Items.Add completes with no exception. After the loop completed, I checked the customers dropdownlist and the entry was, in fact, there. However, once the page loaded, I had the same problem: all of the entries appeared; the test customer simply wasn't there. There was no empty entry or anything; it was simply as if it had never populated.
The only thing that I can think of is that there is some caching going on somewhere, but I just don't know why this is occurring. I cleared the IE cache as well, and I had assumed that between that and the iisreset and database restart, I would be covered. Thanks in advance for any help you can give.
EDIT: I just did a full server restart, and now the information is showing up properly. Clearly, an individual component needed to be restarted in order for this to display properly. Does anyone have any idea as to what that may be? It's obviously not the database or IIS, and I don't want to have to restart the entire server every time data changes.
EDIT: I just had this problem again. This time, I changed a SELECT statement to add one field, changed an ORDER BY statement, updated the web part on the server, and ran it. The ORDER BY was respected, but the new field doesn't show up. Sql Profiler shows me that the new SELECT statement is in the query, Fiddler shows that the HTTP requests are having no problems, and I cleared the IE cache, but that column is just not rendering in the .aspx page. This time, even a full server restart is not helping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
强制浏览器重新加载页面的一种方法是向 URL 添加随机查询参数。
另一种方法是使用 Response.Cache.SetCacheability(HttpCacheability.NoCache );
One way to force the browser to reload the page is to add a random query parameter to the URL.
Another way is to use Response.Cache.SetCacheability(HttpCacheability.NoCache);
您考虑过浏览器缓存吗?看起来很傻,但给我带来的问题次数多得我数不清?
解决此问题的一种方法是使用免费工具 Fiddler(或其他一些 http 流量监视器)来查看返回的内容和返回的内容。在服务器和浏览器之间传递。
Did you consider browser caching? Seems silly but has cause me problems more times than I can count?
One way to troubleshoot this is to use the free tool Fiddler (or some other http traffic monitor) to watch the content going back & forth between server and browser.