Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. No overload for method

No overload for method

Scheduled Pinned Locked Moved C#
csharpdatabasetutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nikneem2005
    wrote on last edited by
    #1

    Hey guys, I'm so sorry because this is probably one of the most stupid questions I ever asked, but hey, I once was a VB programmer and now started C#, you should be happy hearing that ;) Now what's happening, I'm creating a databound control in C# which uses an Sql connection in order to fetch it's data. To establish the connection we need a connection string, and so I check for the existance of if. When the connectionstring property was not set, I want to throw an exception telling the user that the connectionstring was not set. throw new SqlException("Connectionstring not set"); Now when compiling I get the warning No overload for method 'SqlException' takes '1' arguments I cannot find what's really meant here, and how to solve it... Any ideas? I love it when a plan comes together

    S J 2 Replies Last reply
    0
    • N nikneem2005

      Hey guys, I'm so sorry because this is probably one of the most stupid questions I ever asked, but hey, I once was a VB programmer and now started C#, you should be happy hearing that ;) Now what's happening, I'm creating a databound control in C# which uses an Sql connection in order to fetch it's data. To establish the connection we need a connection string, and so I check for the existance of if. When the connectionstring property was not set, I want to throw an exception telling the user that the connectionstring was not set. throw new SqlException("Connectionstring not set"); Now when compiling I get the warning No overload for method 'SqlException' takes '1' arguments I cannot find what's really meant here, and how to solve it... Any ideas? I love it when a plan comes together

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      It means that the SqlException class provides no constructor that takes 1 argument, in your case the error message. Taking a quick look at MSDN shows that the SqlException class provides no constructor at all, so you'll have to throw some other exception. Unless, someone knows a workaround.


      www.troschuetz.de

      J N 2 Replies Last reply
      0
      • N nikneem2005

        Hey guys, I'm so sorry because this is probably one of the most stupid questions I ever asked, but hey, I once was a VB programmer and now started C#, you should be happy hearing that ;) Now what's happening, I'm creating a databound control in C# which uses an Sql connection in order to fetch it's data. To establish the connection we need a connection string, and so I check for the existance of if. When the connectionstring property was not set, I want to throw an exception telling the user that the connectionstring was not set. throw new SqlException("Connectionstring not set"); Now when compiling I get the warning No overload for method 'SqlException' takes '1' arguments I cannot find what's really meant here, and how to solve it... Any ideas? I love it when a plan comes together

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        nikneem2005 wrote: I cannot find what's really meant here Sorry to state the obvious, but what is really meant is what it really says. The "Method" you are calling is actually a constructor (similar in signiture to a method). As the error states, there is no constructor which takes one parameter (argument). You can confirm this by opening object browser in VS, navigating to system.data.sqlclient.SqlException - it has NO public constructors at all. The most likely reason for this is that SqlException was not intended to be used by client code. A quick look with .NET reflector confirms there is a serialization constructor on this object only. Now, to answer your question, create your own exception, inheriting from System.ApplicationException, and throw this instead. Something like "ConfigurationException" would be relevant in this case and could be reused anytime where the app is not configured correctly.

        1 Reply Last reply
        0
        • S Stefan Troschuetz

          It means that the SqlException class provides no constructor that takes 1 argument, in your case the error message. Taking a quick look at MSDN shows that the SqlException class provides no constructor at all, so you'll have to throw some other exception. Unless, someone knows a workaround.


          www.troschuetz.de

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          Stefan Troschütz wrote: Unless, someone knows a workaround A workaround to a no-public-constructor object?!?!? I guess you could instantiate through reflection if you were THAT desperate to have a SqlException.

          1 Reply Last reply
          0
          • S Stefan Troschuetz

            It means that the SqlException class provides no constructor that takes 1 argument, in your case the error message. Taking a quick look at MSDN shows that the SqlException class provides no constructor at all, so you'll have to throw some other exception. Unless, someone knows a workaround.


            www.troschuetz.de

            N Offline
            N Offline
            nikneem2005
            wrote on last edited by
            #5

            Yup, I guess that should be it... Throwing an ArgumentException in case of an SqlException solves the problem.


            I love it when a plan comes together

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups