Connection property has not been initialized
Posted: Mon 01 Jun 2009 19:21
When I call the following block of code I recieve a "Connection property has not been initialized" error when ExecuteScaler is called.
Dim db As Database = DatabaseFactory.CreateDatabase("MOEDB")
Dim sql As String = "SELECT SEQ_BUNDLES.NEXTVAL FROM DUAL"
Dim cmd As DbCommand = db.GetSqlStringCommand(sql)
Dim keyValue As Integer = CType(cmd.ExecuteScalar(), Integer)
If I modify the code to look like the foloowing it works:
Dim db As Database = DatabaseFactory.CreateDatabase("MOEDB")
Dim sql As String = "SELECT SEQ_BUNDLES.NEXTVAL FROM DUAL"
Dim cmd As DbCommand = db.GetSqlStringCommand(sql)
Dim connection As DbConnection = db.CreateConnection()
cmd.Connection = connection
cmd.Connection.Open()
Dim keyValue As Integer = CType(cmd.ExecuteScalar(), Integer)
cmd.Connection.Close()
My question is why isnt the connection suppoed to be created automatically when ExecuteScaler is called?
Thanks
Kevin
Dim db As Database = DatabaseFactory.CreateDatabase("MOEDB")
Dim sql As String = "SELECT SEQ_BUNDLES.NEXTVAL FROM DUAL"
Dim cmd As DbCommand = db.GetSqlStringCommand(sql)
Dim keyValue As Integer = CType(cmd.ExecuteScalar(), Integer)
If I modify the code to look like the foloowing it works:
Dim db As Database = DatabaseFactory.CreateDatabase("MOEDB")
Dim sql As String = "SELECT SEQ_BUNDLES.NEXTVAL FROM DUAL"
Dim cmd As DbCommand = db.GetSqlStringCommand(sql)
Dim connection As DbConnection = db.CreateConnection()
cmd.Connection = connection
cmd.Connection.Open()
Dim keyValue As Integer = CType(cmd.ExecuteScalar(), Integer)
cmd.Connection.Close()
My question is why isnt the connection suppoed to be created automatically when ExecuteScaler is called?
Thanks
Kevin