Cannot get my reports to work
-
Hi Guys, I am trying to build a report onto my application using VS2005(Cannot afford to upgrade even though I want to). The idea is to load data from my database into a dataset Item (Named DS_RPT_AssetStructure.xsd) using the table "TBL_AS" inside the dataset. I then have a report viewer (RV_AssetStructure) that links to a report (RPT_AssetStructure.rdlc). Now, when I run the report, I get back the error "A datasource instances has not been supplied for the datasource 'DS_RPT_AssetStructure_TBL_AS'. I have tried just designing the report to link directly to the dataset, and repointing the Datasources, but nothing seems to work. I really need to get this to work. Please can someone assist me. Here is my code that refreshes the report:
Public Sub AssetStructureReport() Dim Con As New SqlConnection(Startup.TB\_Connect.Text) Dim Cmd As New SqlCommand("EXEC sp\_Rpt\_AssetStructure " & SQL.SetVar(RCM.CB\_Reports\_AssetStructure\_LocationID.Text), Con) RCM.Cursor = Cursors.WaitCursor Dim dsAS As New DS\_RPT\_AssetStructure Dim rs = New DS\_RPT\_AssetStructure.TBL\_ASDataTable Try Con.Open() Cmd.ExecuteNonQuery() Dim da As New SqlDataAdapter("SELECT \* FROM rpt\_RCM\_AssetStructure Order by \[AltSeq\]", Con) da.Fill(rs) Catch ex As Exception MsgBox("Error Running Asset Structure Report." & vbCrLf & ex.Message) Finally Con.Close() Con.Dispose() End Try MsgBox(rs.rows.count) RCM.RV\_AssetStructure.Reset() RCM.RV\_AssetStructure.LocalReport.ReportEmbeddedResource = "REW.RPT\_AssetStructure.rdlc" RCM.RV\_AssetStructure.LocalReport.DataSources.Clear() RCM.RV\_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs)) RCM.RV\_AssetStructure.Refresh() RCM.RV\_AssetStructure.RefreshReport() dsAS.Dispose() RCM.Cursor = Cursors.Arrow End Sub
The msgbox i have there, is to confirm that my dataset has data, and I can confirm, that I am getting a row count back. If I comment out the following rows:
RCM.RV\_AssetStructure.Reset() RCM.RV\_AssetStructure.LocalReport.ReportEmbeddedResource = "REW.RPT\_AssetStructure.rdlc" RCM.RV\_AssetStructure.LocalReport.DataSources.Clear() RCM.RV\_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs)) RCM.RV\_AssetStructure.Refr
-
Hi Guys, I am trying to build a report onto my application using VS2005(Cannot afford to upgrade even though I want to). The idea is to load data from my database into a dataset Item (Named DS_RPT_AssetStructure.xsd) using the table "TBL_AS" inside the dataset. I then have a report viewer (RV_AssetStructure) that links to a report (RPT_AssetStructure.rdlc). Now, when I run the report, I get back the error "A datasource instances has not been supplied for the datasource 'DS_RPT_AssetStructure_TBL_AS'. I have tried just designing the report to link directly to the dataset, and repointing the Datasources, but nothing seems to work. I really need to get this to work. Please can someone assist me. Here is my code that refreshes the report:
Public Sub AssetStructureReport() Dim Con As New SqlConnection(Startup.TB\_Connect.Text) Dim Cmd As New SqlCommand("EXEC sp\_Rpt\_AssetStructure " & SQL.SetVar(RCM.CB\_Reports\_AssetStructure\_LocationID.Text), Con) RCM.Cursor = Cursors.WaitCursor Dim dsAS As New DS\_RPT\_AssetStructure Dim rs = New DS\_RPT\_AssetStructure.TBL\_ASDataTable Try Con.Open() Cmd.ExecuteNonQuery() Dim da As New SqlDataAdapter("SELECT \* FROM rpt\_RCM\_AssetStructure Order by \[AltSeq\]", Con) da.Fill(rs) Catch ex As Exception MsgBox("Error Running Asset Structure Report." & vbCrLf & ex.Message) Finally Con.Close() Con.Dispose() End Try MsgBox(rs.rows.count) RCM.RV\_AssetStructure.Reset() RCM.RV\_AssetStructure.LocalReport.ReportEmbeddedResource = "REW.RPT\_AssetStructure.rdlc" RCM.RV\_AssetStructure.LocalReport.DataSources.Clear() RCM.RV\_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs)) RCM.RV\_AssetStructure.Refresh() RCM.RV\_AssetStructure.RefreshReport() dsAS.Dispose() RCM.Cursor = Cursors.Arrow End Sub
The msgbox i have there, is to confirm that my dataset has data, and I can confirm, that I am getting a row count back. If I comment out the following rows:
RCM.RV\_AssetStructure.Reset() RCM.RV\_AssetStructure.LocalReport.ReportEmbeddedResource = "REW.RPT\_AssetStructure.rdlc" RCM.RV\_AssetStructure.LocalReport.DataSources.Clear() RCM.RV\_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs)) RCM.RV\_AssetStructure.Refr
T0PGun wrote:
Dim Cmd As New SqlCommand("EXEC sp_Rpt_AssetStructure " & SQL.SetVar(RCM.CB_Reports_AssetStructure_LocationID.Text), Con)
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
T0PGun wrote:
Dim Cmd As New SqlCommand("EXEC sp_Rpt_AssetStructure " & SQL.SetVar(RCM.CB_Reports_AssetStructure_LocationID.Text), Con)
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thanks for the concern Richard, but it is not. The purpose of the SQL.SetVar function turns the whole thing into a string make SQLi harder to do, and then to further prevent it, the code in the SP cannot handle SQLi, and will instead fail with an error msg. Also, the CM_Reports_AssetStructure_LocationID object is also defined as a style DropDownList, so the users are restricted to certain values. I don't mean to sound rude and ungrateful, but I do appreciate your concern, but right now, I am more concerned about making the report work.
-
Thanks for the concern Richard, but it is not. The purpose of the SQL.SetVar function turns the whole thing into a string make SQLi harder to do, and then to further prevent it, the code in the SP cannot handle SQLi, and will instead fail with an error msg. Also, the CM_Reports_AssetStructure_LocationID object is also defined as a style DropDownList, so the users are restricted to certain values. I don't mean to sound rude and ungrateful, but I do appreciate your concern, but right now, I am more concerned about making the report work.
But you're still using string concatenation to build your query. Can you be 100% sure that your
SQL.SetVar
function covers every single possible attack vector? Sure enough to justify having potentially vulnerable code for the sake of saving one extra line of code to add the parameter to your command in the correct way? Using parameterized queries in .NET isn't hard:Dim Cmd As New SqlCommand("EXEC sp_Rpt_AssetStructure @Param = @Param", Con)
Cmd.Parameters.AddWithValue("@Param", RCM.CB_Reports_AssetStructure_LocationID.Text)' -or-
Dim Cmd As New SqlCommand("sp_Rpt_AssetStructure", Con)
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Parameters.AddWithValue("@Param", RCM.CB_Reports_AssetStructure_LocationID.Text)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
But you're still using string concatenation to build your query. Can you be 100% sure that your
SQL.SetVar
function covers every single possible attack vector? Sure enough to justify having potentially vulnerable code for the sake of saving one extra line of code to add the parameter to your command in the correct way? Using parameterized queries in .NET isn't hard:Dim Cmd As New SqlCommand("EXEC sp_Rpt_AssetStructure @Param = @Param", Con)
Cmd.Parameters.AddWithValue("@Param", RCM.CB_Reports_AssetStructure_LocationID.Text)' -or-
Dim Cmd As New SqlCommand("sp_Rpt_AssetStructure", Con)
Cmd.CommandType = CommandType.StoredProcedure
Cmd.Parameters.AddWithValue("@Param", RCM.CB_Reports_AssetStructure_LocationID.Text)
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Hi Guys, I am trying to build a report onto my application using VS2005(Cannot afford to upgrade even though I want to). The idea is to load data from my database into a dataset Item (Named DS_RPT_AssetStructure.xsd) using the table "TBL_AS" inside the dataset. I then have a report viewer (RV_AssetStructure) that links to a report (RPT_AssetStructure.rdlc). Now, when I run the report, I get back the error "A datasource instances has not been supplied for the datasource 'DS_RPT_AssetStructure_TBL_AS'. I have tried just designing the report to link directly to the dataset, and repointing the Datasources, but nothing seems to work. I really need to get this to work. Please can someone assist me. Here is my code that refreshes the report:
Public Sub AssetStructureReport() Dim Con As New SqlConnection(Startup.TB\_Connect.Text) Dim Cmd As New SqlCommand("EXEC sp\_Rpt\_AssetStructure " & SQL.SetVar(RCM.CB\_Reports\_AssetStructure\_LocationID.Text), Con) RCM.Cursor = Cursors.WaitCursor Dim dsAS As New DS\_RPT\_AssetStructure Dim rs = New DS\_RPT\_AssetStructure.TBL\_ASDataTable Try Con.Open() Cmd.ExecuteNonQuery() Dim da As New SqlDataAdapter("SELECT \* FROM rpt\_RCM\_AssetStructure Order by \[AltSeq\]", Con) da.Fill(rs) Catch ex As Exception MsgBox("Error Running Asset Structure Report." & vbCrLf & ex.Message) Finally Con.Close() Con.Dispose() End Try MsgBox(rs.rows.count) RCM.RV\_AssetStructure.Reset() RCM.RV\_AssetStructure.LocalReport.ReportEmbeddedResource = "REW.RPT\_AssetStructure.rdlc" RCM.RV\_AssetStructure.LocalReport.DataSources.Clear() RCM.RV\_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs)) RCM.RV\_AssetStructure.Refresh() RCM.RV\_AssetStructure.RefreshReport() dsAS.Dispose() RCM.Cursor = Cursors.Arrow End Sub
The msgbox i have there, is to confirm that my dataset has data, and I can confirm, that I am getting a row count back. If I comment out the following rows:
RCM.RV\_AssetStructure.Reset() RCM.RV\_AssetStructure.LocalReport.ReportEmbeddedResource = "REW.RPT\_AssetStructure.rdlc" RCM.RV\_AssetStructure.LocalReport.DataSources.Clear() RCM.RV\_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs)) RCM.RV\_AssetStructure.Refr
T0PGun wrote:
A datasource instances has not been supplied for the datasource 'DS_RPT_AssetStructure_TBL_AS'.
T0PGun wrote:
RCM.RV_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs))
Based on the error message, it looks like the data source in your report is called
DS_RPT_AssetStructure_TBL_AS
, but you're passing a data source calledAS
. Try changing the name to match:RCM.RV_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("DS_RPT_AssetStructure_TBL_AS", rs))
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
T0PGun wrote:
A datasource instances has not been supplied for the datasource 'DS_RPT_AssetStructure_TBL_AS'.
T0PGun wrote:
RCM.RV_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("AS", rs))
Based on the error message, it looks like the data source in your report is called
DS_RPT_AssetStructure_TBL_AS
, but you're passing a data source calledAS
. Try changing the name to match:RCM.RV_AssetStructure.LocalReport.DataSources.Add(New ReportDataSource("DS_RPT_AssetStructure_TBL_AS", rs))
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer