奇怪的静态类问题

发布于 2024-08-20 01:50:57 字数 1086 浏览 5 评论 0原文

下面是我非常简单的静态类。不知道出了什么问题。 我在一个具有正确“using”语句的非静态类中使用它。智能感知看到类及其一种方法。

我收到错误

名称“SQLUserDataManager”不 存在于当前上下文中”。

public static class SQLUserDataManager
    {
        public static SqlConnection connection;
        private static bool connectionMade;

        static SQLUserDataManager()
        {


        }

        public static void SpecifyConnection(string username, string password, string database)
        {

            string connectionString = "user id=" + username +
                                        ";password=" + password + ";server=127.0.0.1" +
                                        ";Trusted_Connection=yes" +
                                        ";database=NetunityUsers" +
                                        ";connection timeout=30";

        }
    }

更新: 这是我正在使用它的行。

 SQLUserDataManager.SpecifyConnection("admin", "password", "Users");

问题已解决

我有一个 DLL,其中包含编译时出错的文件。在这个 DLL 中,我还没有包含包含该文件的新文件。我包含了该文件,一切都很好! ^_^

Below is my very simple static class. Not sure what is wrong.
I am using it in a non static class that has a correct "using" statement. Intellisense sees the class and its one method.

I am getting the error

The name 'SQLUserDataManager' does not
exist in the current context".

public static class SQLUserDataManager
    {
        public static SqlConnection connection;
        private static bool connectionMade;

        static SQLUserDataManager()
        {


        }

        public static void SpecifyConnection(string username, string password, string database)
        {

            string connectionString = "user id=" + username +
                                        ";password=" + password + ";server=127.0.0.1" +
                                        ";Trusted_Connection=yes" +
                                        ";database=NetunityUsers" +
                                        ";connection timeout=30";

        }
    }

Update:
This is the line I am using it in.

 SQLUserDataManager.SpecifyConnection("admin", "password", "Users");

Problem Solved

I have a DLL that includes the file that was having errors compiling. In this DLL I had yet to include my new file which contains this file. I included the file and all is good! ^_^

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

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

发布评论

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

评论(2

装迷糊 2024-08-27 01:50:57

错误发生在哪里?
SQLUserDataManager 类是否位于另一个命名空间中,然后是您引用 SQLUserDataManager 的类?

Where does the error occur ?
Is the SQLUserDataManager class in another namespace then the class where you refer to SQLUserDataManager ?

悲喜皆因你 2024-08-27 01:50:57

静态和非静态几乎肯定是无关紧要的——尽管如果您能向我们展示您如何尝试使用它将会有所帮助。

这是在 ASP.NET 中吗?我想知道这是否与 ASP.NET 最终构建的方式以及哪些代码位于何处有关。您能给我们提供更多详细信息吗?

The staticness and non-staticness are almost certainly irrelevant - although it would help if you could show us how you're trying to use it.

Is this in ASP.NET, by any chance? I wonder whether it's to do with the way that ASP.NET ends up being built, and what code lives where. Could you give us more details?

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