blah blah blah is here! blah blah » Close

up0down
link

I'm calling a Store Procedure from C# and for some reason I'm getting this error after 7 months. No code has been change. The SP works well in SQL2000.
Here is the error: System.Data.SqlClient.SqlException "Invalid length parameter passed to the substring function."
Here is the code:
SqlDataAdapter Adapter = new SqlDataAdapter(Sql, Conn);
DataSet ds = new DataSet();
Adapter.Fill(ds);
Conn.Close();
return ds;

please help

last answered 2 years ago

1 answers

up0down
link

Put this code try{..}catch(System.Data.SqlClient.SqlException sqlEx)
{
MessageBox.Show(sqlEx.Message+"\r\n"+sqlEx.StackTrace);
}
And Post that complete message here. So it would help us in pin pointing exactly where it is failing.

up0down
link

I found a resolution to this. I did a DB backup and restored the DB to another instance of the DB. Repointed my app to the new DB and all works well. I'm not sure why the old DB had an issue but I will try to use the catch and post the error message for you soon.
THANKS

up0down
link

Here is the error msg:
Invalid length parameter passed to the substring function.
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, TdsParserState state)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, TdsParserState state)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior run, SqlCommand cmdHandler, SqlDataReader dataStream)
at System.Data.SqlClient.SqlDataReader.get_HasMoreResults()
at System.Data.SqlClient.SqlDataReader.NextResult()
at System.Data.Common.DbDataAdapter.FillNextResult(IDataReader dataReader)
at System.Data.Common.DbDataAdapter.FillFromReader(Object data, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
at System.Data.Common.DbDataAdapter.Fill(Object data, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at RandomIE.Form1.button1_Click(Object sender, EventArgs e) in c:\randomie\form1.cs:line 149

up0down
link

Congrats for gettting the thing back to normal. Thanks for posting the SQL Exception Stack Trace here. I wanted to clarify myself that your code is not making any call to Substring method, reason behind this is I have seen similar kind of problem sometime back. One of my friend was developing Web methods for some of the stored procs in his project. He also actually created a new instance of the datbase and all went well. That time we ran the SqlProfiler too, to check where the problem went wrong. But we missed that, and he was in a hurry, and his project was ending. So we missed opportunity to fully diagnose it. :-)

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback