Question : Operation is not allowed when the object is closed

I am trying to call an SQL query from Excel using VB and I am getting this error when I try to select the results. Can someone help please?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
SQL--------------------------------------------
ALTER proc [dbo].[Month_compare2] @parmin varchar(7)
as
declare @year int, @month int  
declare @result table(ivh_revtype1 varchar(10), [year] int, name varchar(100), sum_ivd_charge float)
set @year = 2009  
set @month = 06  
while @year <= left(@parmin, 4)  
begin  
insert into @result
select   
        h.ivh_revtype1,
		@year,  
		case when left(i.cht_itemcode,2) like 'LH%' then 'Line Haul' else 'Fuel Surcharge' end,  
        (select sum(i.ivd_charge))   
from invoicedetail as i inner join invoiceheader as h on i.ivh_hdrnumber = h.ivh_hdrnumber  
where month(h.ivh_deliverydate) = right(@parmin,2) and 
	(i.cht_itemcode like 'LH%' or left(i.cht_itemcode,2) = 'FS') and  
    year(h.ivh_deliverydate) = @year   
group by h.ivh_revtype1, left(i.cht_itemcode,2)
set @year = @year + 1  
end
--Accessorials
set @year = 2009  
set @month = 06  
while @year <= left(@parmin, 4)   
begin  
insert into @result
select   
        h.ivh_revtype1,
		@year,  
		'Accessorials',
		(select sum(i.ivd_charge))  
from invoicedetail as i inner join invoiceheader as h on i.ivh_hdrnumber = h.ivh_hdrnumber  
where month(h.ivh_deliverydate) = right(@parmin,2) and 
	(i.cht_itemcode not like 'LH%' and i.cht_itemcode not like 'FS%') and  
    year(h.ivh_deliverydate) = @year   
group by h.ivh_revtype1
set @year = @year + 1  
end
--Totals
set @year = 2009  
set @month = 06  
while @year <= left(@parmin, 4)   
begin  
insert into @result
select   
        h.ivh_revtype1,
		@year,  
		' Totals',
		(select sum(i.ivd_charge))  
from invoicedetail as i inner join invoiceheader as h on i.ivh_hdrnumber = h.ivh_hdrnumber  
where month(h.ivh_deliverydate) = right(@parmin,2) and   
    year(h.ivh_deliverydate) = @year   
group by h.ivh_revtype1
set @year = @year + 1  
end

select * from @result order by 1,2,3 desc

VB-------------------

Sub Get_Revenue()
Call ClearForm
Dim command As String
Dim parm As String
parm = Sheet1.Range("G7").Value
' Create a connection object.
Set SuiteConn = New ADODB.Connection
' Provide the connection string.
Dim strConn As String
'Use the SQL Server OLE DB Provider.
strConn = "PROVIDER=SQLOLEDB;"
'Connect to the database on remote server.
strConn = strConn & "Data Source=MyIp; Initial Catalog=MyDataBase;"
'Use an integrated login.
strConn = strConn & " INTEGRATED SECURITY=sspi;"
'Now open the connection.
SuiteConn.Open strConn
' Create a recordset object.
Dim rsCas As ADODB.Recordset
Set rsCas = New ADODB.Recordset
'MsgBox parm
With rsCas
    ' Assign the Connection object.
    .ActiveConnection = SuiteConn
    ' Extract the required records.
        .Open "Month_compare2 '" & parm & "'"
        ' Copy the records into cell A1 on Sheet1.
        Sheet1.Range("A9").CopyFromRecordset rsCas
    .Close
End With
SuiteConn.Close
Set rsCas = Nothing
Set RSuiteConn = Nothing
End Sub

Answer : Operation is not allowed when the object is closed

Hi mate,
I used XPO a lot a few years ago and still have an application on a customer on top of that.

From my experience, XPO works pretty well if your query needs are not too complex.
The deployment is also great, as it creates your schema automatically if the database isn't found, but usually with the schema goes some default data too and we end still needing to create scripts.

Another difference is that XPO work on the opposite direction of most ORMs.
Usually the ORM logic is to create the database and it will generate the classes, on XPO you create the classes and it generates the database which can be a lot of work to configure specially if the DB is big and with a lot of relations.

Entity Framework (EF), in my opinion is a lot more flexible when it comes to querying.
XPO also has a Linq to XPO but although it looks nice, feels like heavier to me.
The integration with SQL Procedures and Functions is transparent and the modeling view is way better than than previous LINQ to SQL  version (which looks like its going to die soon btw).

Also on EF, the code is generated using T4 templates, which is a templating language.
You actually have access to these templates so you can customize them if you need it to generate more code, something specific for your project.
You also have access to all the "action", all the code is generated, you can debug everything that happens behind the scenes.

So, for me, and as a big DevX fan, I'm not pleased but I prefer EF than XPO.

A side note tho is that I also use SubSonic, a custom generator that I've made and also MyGeneration.
All cool code generators.

Cheers!
Alex
Random Solutions  
 
programming4us programming4us