@@ -2619,7 +2619,6 @@ public void PrepareClose()
26192619 public GxConnectionCache ( IGxConnection gxconn , int maxSize )
26202620 {
26212621 preparedCommandsCache = new Dictionary < string , GxItemCommand > ( MAX_SIZE ) ;
2622- InitCommands ( ) ;
26232622 preparedStmtCache = new GxPreparedStatementCache ( gxconn , maxSize ) ;
26242623 conn = gxconn ;
26252624 dataAdapterCacheQueue = new List < DbDataAdapterElem > ( ) ;
@@ -2629,7 +2628,6 @@ public GxConnectionCache(IGxConnection gxconn)
26292628 {
26302629 preparedCommandsCache = new Dictionary < string , GxItemCommand > ( MAX_SIZE ) ;
26312630 preparedStmtCache = new GxPreparedStatementCache ( gxconn , MAX_SIZE ) ;
2632- InitCommands ( ) ;
26332631 conn = gxconn ;
26342632 dataAdapterCacheQueue = new List < DbDataAdapterElem > ( ) ;
26352633 }
@@ -3012,118 +3010,120 @@ public void Clear()
30123010 if ( commandsToRemove != null ) commandsToRemove . Clear ( ) ;
30133011 }
30143012
3015- private void InitCommands ( )
3013+ internal void InitCommands ( )
30163014 {
3017- int commandTimeout = 0 ;
3015+ if ( fetchCommand == null )
3016+ {
3017+ int commandTimeout = 0 ;
30183018
3019- //----------------Fetch command
3020- fetchCommand = new SqlCommand ( "sp_cursorfetch" ) ;
3021- fetchCommand . CommandType = CommandType . StoredProcedure ;
3022- fetchCommand . CommandTimeout = commandTimeout ;
3023- SqlParameter p1 = fetchCommand . Parameters . Add ( "cursor" , SqlDbType . Int ) ;
3024- p1 . Direction = ParameterDirection . Input ;
3019+ //----------------Fetch command
3020+ fetchCommand = new SqlCommand ( "sp_cursorfetch" ) ;
3021+ fetchCommand . CommandType = CommandType . StoredProcedure ;
3022+ fetchCommand . CommandTimeout = commandTimeout ;
3023+ SqlParameter p1 = fetchCommand . Parameters . Add ( "cursor" , SqlDbType . Int ) ;
3024+ p1 . Direction = ParameterDirection . Input ;
30253025
3026- SqlParameter p2 = fetchCommand . Parameters . Add ( "fetchtype" , SqlDbType . Int ) ;
3027- p2 . Direction = ParameterDirection . Input ;
3028- p2 . Value = 2 ; //0x0002 Next row.
3026+ SqlParameter p2 = fetchCommand . Parameters . Add ( "fetchtype" , SqlDbType . Int ) ;
3027+ p2 . Direction = ParameterDirection . Input ;
3028+ p2 . Value = 2 ; //0x0002 Next row.
30293029
3030- SqlParameter p3 = fetchCommand . Parameters . Add ( "rownumber" , SqlDbType . Int ) ;
3031- p3 . Direction = ParameterDirection . Input ;
3032- p3 . Value = 1 ;
3033-
3034- SqlParameter p5 = fetchCommand . Parameters . Add ( "nrows" , SqlDbType . Int ) ;
3035- p5 . Direction = ParameterDirection . Input ;
3030+ SqlParameter p3 = fetchCommand . Parameters . Add ( "rownumber" , SqlDbType . Int ) ;
3031+ p3 . Direction = ParameterDirection . Input ;
3032+ p3 . Value = 1 ;
30363033
3037- //-----------------PrepExec command
3038- prepExecCommand = new SqlCommand ( "sp_cursorprepexec" ) ;
3039- prepExecCommand . CommandType = CommandType . StoredProcedure ;
3040- prepExecCommand . CommandTimeout = commandTimeout ;
3034+ SqlParameter p5 = fetchCommand . Parameters . Add ( "nrows" , SqlDbType . Int ) ;
3035+ p5 . Direction = ParameterDirection . Input ;
30413036
3042- prepExecParms = new SqlParameter [ 7 ] ;
3043- prepExecParms [ 0 ] = new SqlParameter ( "cursor" , SqlDbType . Int ) ;
3044- prepExecParms [ 0 ] . Direction = ParameterDirection . Output ;
3045- prepExecParms [ 0 ] . Value = DBNull . Value ;
3037+ //-----------------PrepExec command
3038+ prepExecCommand = new SqlCommand ( "sp_cursorprepexec" ) ;
3039+ prepExecCommand . CommandType = CommandType . StoredProcedure ;
3040+ prepExecCommand . CommandTimeout = commandTimeout ;
30463041
3047- prepExecParms [ 1 ] = new SqlParameter ( "handle" , SqlDbType . Int ) ;
3048- prepExecParms [ 1 ] . Direction = ParameterDirection . Output ;
3049- prepExecParms [ 1 ] . Value = 0 ;
3042+ prepExecParms = new SqlParameter [ 7 ] ;
3043+ prepExecParms [ 0 ] = new SqlParameter ( "cursor" , SqlDbType . Int ) ;
3044+ prepExecParms [ 0 ] . Direction = ParameterDirection . Output ;
3045+ prepExecParms [ 0 ] . Value = DBNull . Value ;
30503046
3051- prepExecParms [ 2 ] = new SqlParameter ( "parameters" , SqlDbType . NVarChar ) ;
3052- prepExecParms [ 2 ] . Direction = ParameterDirection . Input ;
3053-
3054- prepExecParms [ 3 ] = new SqlParameter ( "stmt" , SqlDbType . NVarChar ) ;
3055- prepExecParms [ 3 ] . Direction = ParameterDirection . Input ;
3056-
3057- prepExecParms [ 4 ] = new SqlParameter ( "scrollopt" , SqlDbType . Int ) ;
3058- prepExecParms [ 4 ] . Direction = ParameterDirection . InputOutput ;
3059-
3060- prepExecParms [ 5 ] = new SqlParameter ( "ccopt" , SqlDbType . Int ) ;
3061- prepExecParms [ 5 ] . Direction = ParameterDirection . InputOutput ;
3062- prepExecParms [ 5 ] . Value = 1 ; //Readonly
3063-
3064- prepExecParms [ 6 ] = new SqlParameter ( "rowcount" , SqlDbType . Int ) ;
3065- prepExecParms [ 6 ] . Direction = ParameterDirection . InputOutput ;
3066-
3067- //-----------------Exec command
3068- execCommand = new SqlCommand ( "sp_cursorexecute" ) ;
3069- execCommand . CommandType = CommandType . StoredProcedure ;
3070- execCommand . CommandTimeout = commandTimeout ;
3071-
3072- execParms = new SqlParameter [ 5 ] ;
3073- execParms [ 0 ] = new SqlParameter ( "cursorId" , SqlDbType . Int ) ;
3074- execParms [ 0 ] . Direction = ParameterDirection . Input ;
3075- execParms [ 1 ] = new SqlParameter ( "handle" , SqlDbType . Int ) ;
3076- execParms [ 1 ] . Direction = ParameterDirection . Output ;
3077- execParms [ 2 ] = new SqlParameter ( "scrollopt" , SqlDbType . Int ) ;
3078- execParms [ 2 ] . Direction = ParameterDirection . InputOutput ;
3079- execParms [ 3 ] = new SqlParameter ( "ccopt" , SqlDbType . Int ) ;
3080- execParms [ 3 ] . Direction = ParameterDirection . InputOutput ;
3081- execParms [ 3 ] . Value = 1 ; //Readonly
3082- execParms [ 4 ] = new SqlParameter ( "rowcount" , SqlDbType . Int ) ;
3083- execParms [ 4 ] . Direction = ParameterDirection . InputOutput ;
3084-
3085- //------------------prepareCursor
3086- prepareCommand = new SqlCommand ( "sp_cursorprepare" ) ;
3087- prepareCommand . CommandType = CommandType . StoredProcedure ;
3088- prepareCommand . CommandTimeout = commandTimeout ;
3089- prepareParms = new SqlParameter [ 6 ] ;
3090-
3091- prepareParms [ 0 ] = new SqlParameter ( "cursor" , SqlDbType . Int ) ;
3092- prepareParms [ 0 ] . Direction = ParameterDirection . Output ;
3093- prepareParms [ 0 ] . Value = DBNull . Value ;
3094-
3095- prepareParms [ 1 ] = new SqlParameter ( "parameters" , SqlDbType . NVarChar ) ;
3096- prepareParms [ 1 ] . Direction = ParameterDirection . Input ;
3047+ prepExecParms [ 1 ] = new SqlParameter ( "handle" , SqlDbType . Int ) ;
3048+ prepExecParms [ 1 ] . Direction = ParameterDirection . Output ;
3049+ prepExecParms [ 1 ] . Value = 0 ;
3050+
3051+ prepExecParms [ 2 ] = new SqlParameter ( "parameters" , SqlDbType . NVarChar ) ;
3052+ prepExecParms [ 2 ] . Direction = ParameterDirection . Input ;
3053+
3054+ prepExecParms [ 3 ] = new SqlParameter ( "stmt" , SqlDbType . NVarChar ) ;
3055+ prepExecParms [ 3 ] . Direction = ParameterDirection . Input ;
30973056
3098- prepareParms [ 2 ] = new SqlParameter ( "stmt" , SqlDbType . NVarChar ) ;
3099- prepareParms [ 2 ] . Direction = ParameterDirection . Input ;
3057+ prepExecParms [ 4 ] = new SqlParameter ( "scrollopt" , SqlDbType . Int ) ;
3058+ prepExecParms [ 4 ] . Direction = ParameterDirection . InputOutput ;
31003059
3101- prepareParms [ 3 ] = new SqlParameter ( "options" , SqlDbType . Int ) ;
3102- prepareParms [ 3 ] . Direction = ParameterDirection . Input ;
3103- prepareParms [ 3 ] . Value = 1 ;
3060+ prepExecParms [ 5 ] = new SqlParameter ( "ccopt" , SqlDbType . Int ) ;
3061+ prepExecParms [ 5 ] . Direction = ParameterDirection . InputOutput ;
3062+ prepExecParms [ 5 ] . Value = 1 ; //Readonly
31043063
3105- prepareParms [ 4 ] = new SqlParameter ( "scrollopt" , SqlDbType . Int ) ;
3106- prepareParms [ 4 ] . Direction = ParameterDirection . InputOutput ;
3064+ prepExecParms [ 6 ] = new SqlParameter ( "rowcount" , SqlDbType . Int ) ;
3065+ prepExecParms [ 6 ] . Direction = ParameterDirection . InputOutput ;
31073066
3108- prepareParms [ 5 ] = new SqlParameter ( "ccopt" , SqlDbType . Int ) ;
3109- prepareParms [ 5 ] . Direction = ParameterDirection . InputOutput ;
3110- prepareParms [ 5 ] . Value = 4 ;
3067+ //-----------------Exec command
3068+ execCommand = new SqlCommand ( "sp_cursorexecute" ) ;
3069+ execCommand . CommandType = CommandType . StoredProcedure ;
3070+ execCommand . CommandTimeout = commandTimeout ;
31113071
3112- //----------------Close command
3113- closeCommand = new SqlCommand ( "sp_cursorclose" ) ;
3114- closeCommand . CommandType = CommandType . StoredProcedure ;
3115- closeCommand . CommandTimeout = commandTimeout ;
3116- SqlParameter handle4 = closeCommand . Parameters . Add ( "handle" , SqlDbType . Int ) ;
3117- handle4 . Direction = ParameterDirection . Input ;
3072+ execParms = new SqlParameter [ 5 ] ;
3073+ execParms [ 0 ] = new SqlParameter ( "cursorId" , SqlDbType . Int ) ;
3074+ execParms [ 0 ] . Direction = ParameterDirection . Input ;
3075+ execParms [ 1 ] = new SqlParameter ( "handle" , SqlDbType . Int ) ;
3076+ execParms [ 1 ] . Direction = ParameterDirection . Output ;
3077+ execParms [ 2 ] = new SqlParameter ( "scrollopt" , SqlDbType . Int ) ;
3078+ execParms [ 2 ] . Direction = ParameterDirection . InputOutput ;
3079+ execParms [ 3 ] = new SqlParameter ( "ccopt" , SqlDbType . Int ) ;
3080+ execParms [ 3 ] . Direction = ParameterDirection . InputOutput ;
3081+ execParms [ 3 ] . Value = 1 ; //Readonly
3082+ execParms [ 4 ] = new SqlParameter ( "rowcount" , SqlDbType . Int ) ;
3083+ execParms [ 4 ] . Direction = ParameterDirection . InputOutput ;
31183084
3119- //------------------unprepareCursor
3120- unprepareCommand = new SqlCommand ( "sp_cursorunprepare" ) ;
3121- unprepareCommand . CommandType = CommandType . StoredProcedure ;
3122- unprepareCommand . CommandTimeout = commandTimeout ;
3085+ //------------------prepareCursor
3086+ prepareCommand = new SqlCommand ( "sp_cursorprepare" ) ;
3087+ prepareCommand . CommandType = CommandType . StoredProcedure ;
3088+ prepareCommand . CommandTimeout = commandTimeout ;
3089+ prepareParms = new SqlParameter [ 6 ] ;
31233090
3124- SqlParameter cursor1 = unprepareCommand . Parameters . Add ( "cursor" , SqlDbType . Int ) ;
3125- cursor1 . Direction = ParameterDirection . Input ;
3091+ prepareParms [ 0 ] = new SqlParameter ( "cursor" , SqlDbType . Int ) ;
3092+ prepareParms [ 0 ] . Direction = ParameterDirection . Output ;
3093+ prepareParms [ 0 ] . Value = DBNull . Value ;
31263094
3095+ prepareParms [ 1 ] = new SqlParameter ( "parameters" , SqlDbType . NVarChar ) ;
3096+ prepareParms [ 1 ] . Direction = ParameterDirection . Input ;
3097+
3098+ prepareParms [ 2 ] = new SqlParameter ( "stmt" , SqlDbType . NVarChar ) ;
3099+ prepareParms [ 2 ] . Direction = ParameterDirection . Input ;
3100+
3101+ prepareParms [ 3 ] = new SqlParameter ( "options" , SqlDbType . Int ) ;
3102+ prepareParms [ 3 ] . Direction = ParameterDirection . Input ;
3103+ prepareParms [ 3 ] . Value = 1 ;
3104+
3105+ prepareParms [ 4 ] = new SqlParameter ( "scrollopt" , SqlDbType . Int ) ;
3106+ prepareParms [ 4 ] . Direction = ParameterDirection . InputOutput ;
3107+
3108+ prepareParms [ 5 ] = new SqlParameter ( "ccopt" , SqlDbType . Int ) ;
3109+ prepareParms [ 5 ] . Direction = ParameterDirection . InputOutput ;
3110+ prepareParms [ 5 ] . Value = 4 ;
3111+
3112+ //----------------Close command
3113+ closeCommand = new SqlCommand ( "sp_cursorclose" ) ;
3114+ closeCommand . CommandType = CommandType . StoredProcedure ;
3115+ closeCommand . CommandTimeout = commandTimeout ;
3116+ SqlParameter handle4 = closeCommand . Parameters . Add ( "handle" , SqlDbType . Int ) ;
3117+ handle4 . Direction = ParameterDirection . Input ;
3118+
3119+ //------------------unprepareCursor
3120+ unprepareCommand = new SqlCommand ( "sp_cursorunprepare" ) ;
3121+ unprepareCommand . CommandType = CommandType . StoredProcedure ;
3122+ unprepareCommand . CommandTimeout = commandTimeout ;
3123+
3124+ SqlParameter cursor1 = unprepareCommand . Parameters . Add ( "cursor" , SqlDbType . Int ) ;
3125+ cursor1 . Direction = ParameterDirection . Input ;
3126+ }
31273127 }
31283128 }
31293129
@@ -4148,6 +4148,7 @@ public MssqlConnectionWrapper(String connectionString, GxConnectionCache connCac
41484148 }
41494149 override public void Open ( )
41504150 {
4151+ m_connectionCache . InitCommands ( ) ;
41514152 InternalConnection . Open ( ) ;
41524153 if ( ! m_autoCommit )
41534154 {
0 commit comments