通过C#查询时SQL Server 2005区分大小写
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了通过C#查询时SQL Server 2005区分大小写,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2003字,纯文字阅读大概需要3分钟。
内容图文
![通过C#查询时SQL Server 2005区分大小写](/upload/InfoBanner/zyjiaocheng/910/0184286d69c848cc929c566820229eb9.jpg)
我遇到了一个安装在几个客户站点工作的产品的问题,我认为这个问题与他们的数据库服务器上的Collat??ion设置有关.我的代码看起来像这样(我改变了表和变量名称,因为代码是专有的):
using (SqlCommand insertCommand = dbConnection.CreateCommand())
{
insertCommand.CommandText = "INSERT INTO [myTable] ([valueOne] ,[valueTwo] ,[CreationDate]) VALUES (@valueTwo ,@valueTwo ,@creationDate);select IDENT_CURRENT('myTable');";
insertCommand.Parameters.AddWithValue("@valueOne", "Value One");
insertCommand.Parameters.AddWithValue("@valueTwo", "Value Two");
insertCommand.Parameters.AddWithValue("@CreationDate", CreationDate);
dbConnection.Open();
object result = insertCommand.ExecuteScalar();
dbConnection.Close();
}
这适用于大多数站点以及我们的开发和QA计算机,但在这一个站点上我们收到一个错误,上面写着“必须声明标量变量”@creationDate“.我看到的主要差异是该站点的排序规则值设置为SQL_Latin1_General_CP1_CS_AS我们的设置都是SQL_Latin1_General_CP1_CI_AS.我为我们的数据库更改了这个,但是服务器仍然设置为区分大小写的变体.这确实解决了我们使用不同的表的另一个问题(一个是表名,而不是参数名) ,但由于某种原因,它仍然是一个问题.有没有人有任何想法如何解决这个问题比通过和修复我们的代码库中的所有案例差异更快一点?
该站点使用的是SQL Server 2005,我们的代码是用C#和.NET 3.5编写的.
谢谢
-Hollis
解决方法:
服务器的排序规则控制着这些,这是设计的.
从BOL(强调我的):
The collation of an identifier depends on the level at which it is
defined. Identifiers of instance-level objects, such as logins and
database names, are assigned the default collation of the instance.
Identifiers of objects within a database, such as tables, views, and
column names, are assigned the default collation of the database.
Variables, GOTO labels, temporary stored procedures, and temporary
tables can be created when the connection context is associated with
one database and then referenced when the context has been switched to
another database. Therefore, the identifiers for variables, GOTO
labels, and temporary tables are in the default collation of the
instance.
内容总结
以上是互联网集市为您收集整理的通过C#查询时SQL Server 2005区分大小写全部内容,希望文章能够帮你解决通过C#查询时SQL Server 2005区分大小写所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。