No overload for method
-
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
-
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
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 theSqlException
class provides no constructor at all, so you'll have to throw some other exception. Unless, someone knows a workaround.
-
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
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.
-
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 theSqlException
class provides no constructor at all, so you'll have to throw some other exception. Unless, someone knows a workaround.
-
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 theSqlException
class provides no constructor at all, so you'll have to throw some other exception. Unless, someone knows a workaround.
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