0

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! ^_^

bobber205
  • 12,948
  • 27
  • 74
  • 100
  • Your class definition looks fine. Can you show us how your using `SQLUserDataManager`? – dariom Jan 30 '10 at 20:26
  • All of the code above looks fine. It must be to do with your `using` statements in the code where you are using `SQLUserDataManager`. – adrianbanks Jan 30 '10 at 20:38
  • The namespace the class is under is namespace Netunity.Utilities I am doing using Netunity.Utilities; in the file I am trying to use it from. – bobber205 Jan 30 '10 at 20:41
  • In your example the SpecifyConnection method should return a string? Now the SpecifyConnection method is kinda useless. – Yvo Jan 30 '10 at 20:41
  • Can you create a short but complete program which demonstrates the problem? Are you sure you've got the right using directive *in the file which contains that line*? – Jon Skeet Jan 30 '10 at 20:42
  • Odd it works in my Main.cs file but not my the file I need it in. xD – bobber205 Jan 30 '10 at 20:44
  • SpecifyConnection is not finished yet. :) – bobber205 Jan 30 '10 at 20:44
  • @bobber205: Do you have the using directive in that file? You can't just put it in one place - it needs to be in every file using that namespace. – Jon Skeet Jan 30 '10 at 20:44
  • Problem solved. Had to do with a DLL project included in the solution. :) – bobber205 Jan 30 '10 at 20:47

2 Answers2

1

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

Frederik Gheysels
  • 56,135
  • 11
  • 101
  • 154
  • The error occurs in a ctor for another class that is not static. I have pasted the relevent line in my OP. – bobber205 Jan 30 '10 at 20:36
0

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?

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194