项目设置和未设置为实例错误

发布于 2024-07-22 20:37:48 字数 1168 浏览 3 评论 0原文

我希望有人能帮助我指明正确的方向。 我的 Settings.Designer.cs 文件出现 StackOverFlow 错误。 我根据这篇文章手动重新生成了文件此处现在我的设计器文件看起来像这样应该如此,他们告诉我,但是在我的类库(30 个地方)中访问设置文件的所有地方现在都会抛出 需要对象引用错误

这对其他人来说是显而易见的吗? 我做错了什么或者我需要做什么来解决这个问题? 下面分别是我的 Settings.Designer.cs 文件和类库的示例。

 public string CMOSQLConn {
        get {
            return ((string)(this["CMOSQLConn"]));
        }
    }

 public class SupportWorker
{
    public DataSet RetrieveSupportWorkers()
    {
        DataSet ds = new DataSet("table");
        SqlConnection cnn = new SqlConnection(Settings.CMOSQLConn);
        SqlCommand cmd = new SqlCommand("spSelectSupportWorkers", cnn) {CommandType = CommandType.StoredProcedure};
        SqlDataAdapter da = new SqlDataAdapter(cmd);

编辑1

我将发布此内容,希望如果它明显错误并且似乎是正确的,有人会指出它。

我替换了 --> 的所有实例 SqlConnection cnn = new SqlConnection(Settings.CMOSQLConn); 具有以下 -->SqlConnection cnn = new SqlConnection(Settings.Default.CMOSQLConn);

我不知道为什么这使它工作但是......

I am hoping someone can help point me in the right direction. I was having a StackOverFlow error with my Settings.Designer.cs file. I manually regenerated the file according to this post HERE Now my Designer file looks like it is supposed to, so they tell me, but everywhere in my Class Library(30 places) that was accessing the Settings File now throws a Object reference is required error

Is this obvious to everyone else? What am I doing wrong or what do I need to do to fix this? Below are what my Settings.Designer.cs file and an example of the class library, respectively, look like.

 public string CMOSQLConn {
        get {
            return ((string)(this["CMOSQLConn"]));
        }
    }

 public class SupportWorker
{
    public DataSet RetrieveSupportWorkers()
    {
        DataSet ds = new DataSet("table");
        SqlConnection cnn = new SqlConnection(Settings.CMOSQLConn);
        SqlCommand cmd = new SqlCommand("spSelectSupportWorkers", cnn) {CommandType = CommandType.StoredProcedure};
        SqlDataAdapter da = new SqlDataAdapter(cmd);

EDIT 1

I am going to post this in hopes that if it is glaringly wrong and just seems to be correct that someone will point it out.

I replaced all instances of --> SqlConnection cnn = new SqlConnection(Settings.CMOSQLConn); with the following -->SqlConnection cnn = new SqlConnection(Settings.Default.CMOSQLConn);

I have no idea why that makes it work but....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2024-07-29 20:37:48

设置类中的所有属性都是实例属性。 为了使用它们,您需要一个 Settings 类的实例。 执行此操作的标准方法是访问 Settings 类的静态 Default 属性,该属性返回 Settings 的实例。 从那里您可以访问各个属性。

如果它之前在不使用默认值的情况下工作......则存在严重错误。

All of the properties in the settings class are instance properties. In order to use them, you need an instance of the Settings class. The standard way to do this is to access the static Default property on the Settings class, which returns an instance of Settings. From there you can access the individual properties.

If it was working before without using Default...something was seriously wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文