MVC中的SQL Server连接字符串问题 [英] Problem with SQL server connection string in MVC

查看:98
本文介绍了MVC中的SQL Server连接字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很奇怪。



所以我正在开发一个MVC5网站,一切都很顺利,包括使用数据库中的存储过程。



然后我添加了一个新的数据库调用。当我尝试创建 SqlConnection 关键字不支持'初始目录' $ c>带有连接字符串的对象。



如果我注释掉了调用存储过程,所有其他数据库事务(使用相同的连接字符串)继续正常。这让我觉得存储过程有问题,但是sql server manager报告没有错误,我正在使用正确的名称和 SqlParameter 列表。



我不知所措(是的,我在web.config的连接字符串键中包含 providerName 属性)。



更多信息:



0)我在故障点检查了连接字符串,它准确地表示了在web.conf文件中指定的方式。



1)应用启动中的下一个数据库调用(两个调用都采用相同的控制器方法)成功。



2)有问题的存储过程期望一个字符串不能超过36个字符,而我传递的字符串只有32个字符。



3)当我尝试创建SqlConnection对象时失败,因此存储的proc本身不是失败的因素。



4)如果我移动这个调用以跟随另一个数据库调用(成功),当我尝试创建 SqlConnection 对象时,此调用仍然失败。



我的尝试:



此信息基本上与我的问题重复。多么浪费带宽。

This is a weird one.

So I'm cruising along developing a MVC5 web site, and everything is going pretty well, including using stored procs from the database.

Then I added a new call to the database. This call fails with the exception Keyword not supported 'initial catalog' when I try to create a SqlConnection object with the connection string.

If I comment out the call to hit the stored proc, ALL OTHER DATABASE TRANSACTIONS (using the same connection string) PROCEED NORMALLY. This led me to think there was something wrong with the stored proc, but sql server manager reports no errors, and I'm using the correct name and SqlParameter list.

I'm at a loss (and yes, I include the providerName property in the connection string key in web.config).

More Info:

0) I inspected the connection string at the point of failure, and it is an accurate representation of the way it's specified in the web.conf file.

1) The next database call in the app startup (both calls are in the same controller method) succeeds.

2) The stored proc in question is expecting a string that can be no longer than 36 characters, and the string I'm passing is only 32 characters.

3) It fails when I try to create the SqlConnection object, so the stored proc itself is not a factor in the failure.

4) If I move this call to follow another database call (that succeeds), this call still fails when I try to create the SqlConnection object.

What I have tried:

This info would essentially be a duplicate of my question. What a waste of bandwidth.

推荐答案

怪异。如果我的代码没有任何更改,它就会开始工作。我只能耸耸肩......
Weirdness. Without ANY changes to my code, it started working. I can only shrug my shoulders...


用于SQL Server连接字符串的.NET Framework数据提供程序 - ConnectionStrings.com [ ^ ]


这篇关于MVC中的SQL Server连接字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆