首页 \ 问答 \ MVC4:SQL登录失败。(MVC4: SQL Login failed. Error code 1. Only happening on one page)

MVC4:SQL登录失败。(MVC4: SQL Login failed. Error code 1. Only happening on one page)

我刚刚遇到了有史以来最奇怪(也是最令人沮丧)的错误之一。 我有一个刚刚被放到登台服务器上的网站(尚未上线)。 除了一个特定的页面,一切似乎都运行正常。 有一个方法被调用,它调用一个存储过程,但我得到一个SqlException ,它说Login failed for [the-login-name]错误状态为1.奇怪的是,从同一个方法调用完全相同的方法另一个页面,并使用完全相同的SQL连接详细信息,它很好..此外..这只发生在登台服务器上..不在我的开发机器上。 以前有人见过这样的事吗? 我无法弄清楚导致这种情况的2之间会有什么不同。

我们都看到it works on my dev machine问题上工作..但是我从来没有看到调用相同方法的2个页面只会导致其中一个抛出异常...这只是简单的怪异。

我正在使用MVC4和SQL Server 2012。


I have just come across what has to be one of the weirdest (and most frustrating) errors ever. I have a site which has just been put onto a staging server (not yet live). Everything seems to be working fine except one particular page. There is a method being called which invokes a stored procedure, but I am getting a SqlException which says Login failed for [the-login-name] and an error state of 1. The curious thing is that the exact same method is being called from another page and is using the exact same sql connection details and it's fine.. moreover.. this is ONLY happening on the staging server.. not on my dev machine. Has anyone here ever seen anything like this before? I can't quite figure out what could be different between the 2 that would cause this.

We've all seen the it works on my dev machine problem.. but I have never seen where 2 pages calling the same method causes only one of them to throw an exception.. that's just plain freaky.

I am using MVC4 and SQL Server 2012.


原文:https://stackoverflow.com/questions/14040298
更新时间:2022-01-20 21:01

最满意答案

您还可以创建自定义模型字段类型 - 请参阅http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#howto-custom-model-fields

在这种情况下,您可以从内置的IntegerField继承,并覆盖其验证逻辑。

我想到的越多,我就意识到对于许多Django应用程序来说,这有多有用。 也许一个IntegerRangeField类型可以作为Django开发人员考虑添加到trunk的补丁来提交。

这是为我工作:

from django.db import models

class IntegerRangeField(models.IntegerField):
    def __init__(self, verbose_name=None, name=None, min_value=None, max_value=None, **kwargs):
        self.min_value, self.max_value = min_value, max_value
        models.IntegerField.__init__(self, verbose_name, name, **kwargs)
    def formfield(self, **kwargs):
        defaults = {'min_value': self.min_value, 'max_value':self.max_value}
        defaults.update(kwargs)
        return super(IntegerRangeField, self).formfield(**defaults)

然后在你的模型类中,你可以像这样使用它(字段是放在上面的代码的模块):

size = fields.IntegerRangeField(min_value=1, max_value=50)

或一个负和正的范围(如振荡器范围):

size = fields.IntegerRangeField(min_value=-100, max_value=100)

真的很酷的是如果可以用这样的范围操作符来调用它:

size = fields.IntegerRangeField(range(1, 50))

但是,这将需要更多的代码,因为您可以指定“skip”参数 - 范围(1,50,2) - 有趣的想法,但...


You could also create a custom model field type - see http://docs.djangoproject.com/en/dev/howto/custom-model-fields/#howto-custom-model-fields

In this case, you could 'inherit' from the built-in IntegerField and override its validation logic.

The more I think about this, I realize how useful this would be for many Django apps. Perhaps a IntegerRangeField type could be submitted as a patch for the Django devs to consider adding to trunk.

This is working for me:

from django.db import models

class IntegerRangeField(models.IntegerField):
    def __init__(self, verbose_name=None, name=None, min_value=None, max_value=None, **kwargs):
        self.min_value, self.max_value = min_value, max_value
        models.IntegerField.__init__(self, verbose_name, name, **kwargs)
    def formfield(self, **kwargs):
        defaults = {'min_value': self.min_value, 'max_value':self.max_value}
        defaults.update(kwargs)
        return super(IntegerRangeField, self).formfield(**defaults)

Then in your model class, you would use it like this (field being the module where you put the above code):

size = fields.IntegerRangeField(min_value=1, max_value=50)

OR for a range of negative and positive (like an oscillator range):

size = fields.IntegerRangeField(min_value=-100, max_value=100)

What would be really cool is if it could be called with the range operator like this:

size = fields.IntegerRangeField(range(1, 50))

But, that would require a lot more code since since you can specify a 'skip' parameter - range(1, 50, 2) - Interesting idea though...

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。