Error Occurred With Parameter 0 Sqlparameter.size
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Output SqlParameter Error: the Size property has an invalid size of 0 up vote 0 down vote favorite I know there are a few other threads/questions about this error, but I wanted to get a bit more insight if possible. We've seen this error occur intermittently for a particular piece of code where we have an Integer type output parameter. This is how we're defining the parameter: SqlParameter errorParam = new SqlParameter("@ErrorCode", errorCode); errorParam.Direction = ParameterDirection.Output; You'll notice no size and no DBType is specified. It seems the error doesn't always occur, but sometimes this will be thrown: the Size property has an invalid size of 0. at System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc) at System.Data.SqlClient.SqlCommand.SetUpRPCParameters(_SqlRPC rpc, Int32 startCount, Boolean inSchema, SqlParameterCollection parameters) I'm assuming I need to add the DBType and Size settings, but what might be underlying reason be that this is occurring, and only in some occasions? Note, the parameter in SQL is defined as: @ErrorCode INT OUT , c# sql stored-procedures sqlparameter output-parameter share|improve this question asked Jan 29 at 18:36 Dustin Kofoed 1161112 Why could you not simply do: cmd.Parameters.Add("@ErrorCode", SqlDbType.Int) = errorCode; what are the drawbacks to this? –JonH Jan 29 at 18:39 What is the datatype of the variable errorcode? –Steve Jan 29 at 18:40 @Steve - Thats the issue he needs to specify SqlDbType.Int –JonH Jan 29 at 18:40 add a comment| 1 Answer 1 active oldest votes up vote 0 down vote accepted The size is needed if the type is string, your type is int. You need to specify SqlDbType.Int and you'll avoid t
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Ado.net - the Size property has an invalid size of 0 up vote 43 down vote favorite 3 I'm trying to get output value http://stackoverflow.com/questions/35091655/output-sqlparameter-error-the-size-property-has-an-invalid-size-of-0 from DB via ADO.net. There's a client code: using (var connection = new SqlConnection(ConnectionString)) { connection.Open(); SqlCommand command = new SqlCommand("pDoSomethingParamsRes", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@i", 1); var outParam = new SqlParameter("@out", SqlDbType.VarChar); outParam.Direction = ParameterDirection.Output; command.Parameters.Add(outParam); command.ExecuteNonQuery(); Console.WriteLine(command.Parameters["@out"].Value.ToString()); } When I run this I get the following exception: the Size property has an invalid size of 0 According to manual SqlParameter.Size Property I might omit size. Why do I get this exception? How to http://stackoverflow.com/questions/3759285/ado-net-the-size-property-has-an-invalid-size-of-0 make it work without passing size? Thank you for your help! c# sql-server ado.net share|improve this question asked Sep 21 '10 at 10:13 StuffHappens 2,519114483 Why you want to avoid setting the Size property... –The King Sep 21 '10 at 10:20 add a comment| 6 Answers 6 active oldest votes up vote 46 down vote accepted VarChar and NVarChar are variable width character fields (thus var+char). You have to set the length, otherwise the default is zero. share|improve this answer answered Sep 21 '10 at 10:18 Sachin Shanbhag 32.4k65888 What if I supply the size = 1000 for int? Will I get an exception? –StuffHappens Sep 21 '10 at 10:20 @StuffHappens - The varchar and NVarchar always adjust to the data length no matter what size you give. So you can set any size (MAX 4000 for Nvarchar and 8000 for varchar). It wont hurt. –Sachin Shanbhag Sep 21 '10 at 10:22 2 Just to add that if you assign a value to the parameter, the size of that value will be used as the default instead of 0 (i.e. you can omit the size). –AdaTheDev Sep 21 '10 at 10:22 add a comment| up vote 31 down vote Parameter Size is required for variable size Output parameters. Generally ADO.NET decides the size of the paramet
this is urgent (Size property has an invalid size of 0) The SitePoint Forums have moved. You can now http://www.sitepoint.com/forums/showthread.php?493190-pls-help-this-is-urgent-(Size-property-has-an-invalid-size-of-0) find them here. This forum is now closed to new posts, but you can browse existing content. You can find out more information about the move and how to open a new account (if necessary) here. If you get stuck you can get support by emailing forums@sitepoint.com If this is your first visit, be sure to error occurred check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. SitePoint Sponsor User Tag List Results 1 to 3 of 3 Thread: pls help this is error occurred with urgent (Size property has an invalid size of 0) Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Jul 24, 2007,06:47 #1 nellyihu View Profile View Forum Posts SitePoint Enthusiast Join Date Jun 2005 Posts 74 Mentioned 0 Post(s) Tagged 0 Thread(s) pls help this is urgent (Size property has an invalid size of 0) hello all, i have been try to access an output paramater in asp.net version 2.0 and it comes up with this error details below: HTML Code: Server Error in '/Spectrum' Application. -------------------------------------------------------------------------------- String[1]: the Size property has an invalid size of 0. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: String[1]: the Size property has an invalid size of 0. Source Error: Line 69: With con Line 70: con.Open() Line 71: SpecCmd.ExecuteNonQuery() Line 72: Return CType(SpecCmd.Parameters("@RefNo"