Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Connection Error

Status
Not open for further replies.

AnthonyJ20

Programmer
Aug 24, 2005
32
US
Hope someone can help me. I'm having a problem making a connection to an SQL Server database using .Net. This is the error



Server Error in '/WebApplication1' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'CustomerBoxes' is not declared.

Source Error:



Line 75:
Line 76: Dim dsProducts As New DataSet
Line 77: cmdProducts.Fill(CustomerBoxes, "tblDataTable")
Line 78:
Line 79: repList.DataSource = _


Source File: c:\inetpub\ Line: 77



I'm somewhat new to SQL Server. I've imported two tables. CustomerBoxes and tblDataTableNew. The two table are related. The tblDataTable DataTableID is related to the CustomerBoxes CustomerID. Can anyone point me in the right direction? Here is what my connection looks like.




Sub Page_Load(Source As Object, E As EventArgs)

' Variable declaration

' Obtain CategoryID from QueryString
Dim DataTable As Integer = _
CInt(Request.Params("DataTable"))


' TO DO: read data from database
Dim strConn As String
Dim conn As SqlConnection
strConn = _
"server=REMITCOCLTVOL;uid=APhillips;pwd=james113;database=RemitcoWebServer"
conn = New SqlConnection(strConn)


Dim cmdProducts As SqlDataAdapter
cmdProducts = _
New SqlDataAdapter("ProductsByCategory", conn)
cmdProducts.SelectCommand.CommandType = _
CommandType.StoredProcedure


Dim paramCategoryID As SqlParameter
paramCategoryID = _
new SqlParameter("@CustomerID", SqlDbType.Int, 4)
paramCategoryID.Value = DataTable
cmdProducts.SelectCommand.Parameters.Add(paramCategoryID)


Dim dsProducts As New DataSet
cmdProducts.Fill(CustomerBoxes, "tblDataTable")

repList.DataSource = _
dsProducts.Tables("tblDataTable").DefaultView
repList.DataBind()

End Sub

 
"Customerboxes" in this code is referring to the dataset name, not the table name in the DB. The dataset has to be declared somewhere. Check the syntax in help.

SQLDataAdapter.Fill(<data set>, <data table>)

 
It looks as though you haven't declared your CustomerBoxes DataSet anywhere...


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Thanks for the response guys. Your thoughts helped me get past that error. But now toward the end of my code, just before diplaying records, I get this error.



Server Error in '/WebApplication1' Application.
--------------------------------------------------------------------------------

Login failed for user 'APhillips'. Reason: Not associated with a trusted SQL Server connection.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'APhillips'. Reason: Not associated with a trusted SQL Server connection.

Source Error:


Line 74:
Line 75: Dim dsProducts As New DataSet
Line 76: cmdProducts.Fill(dsProducts, "tblDataTable")
Line 77:
Line 78: repList.DataSource = _


Source File: c:\inetpub\ Line: 76



My userID for my PC is APhillips and I did enter the correct password. The SQL Server I'm trying to connect to is REMITCOCLTVOL and the the database is called RemitcoWebServer. I'm using Windows Authentication and automatic login on the server. What's wrong? Here is the updated connection and DataSet.



Sub Page_Load(Source As Object, E As EventArgs)

' Variable declaration

' Obtain CategoryID from QueryString
Dim CustomerID As Integer = _
CInt(Request.Params("CustomerID"))


' TO DO: read data from database
Dim strConn As String
Dim conn As SqlConnection
strConn = _
"server=REMITCOCLTVOL;uid=APhillips;pwd=james123;database=RemitcoWebServer"
conn = New SqlConnection(strConn)


Dim cmdProducts As SqlDataAdapter
cmdProducts = _
New SqlDataAdapter("ProductsByCategory", conn)
cmdProducts.SelectCommand.CommandType = _
CommandType.StoredProcedure


Dim paramCategoryID As SqlParameter
paramCategoryID = _
new SqlParameter("@CustomerID", SqlDbType.Int, 4)
paramCategoryID.Value = CustomerID
cmdProducts.SelectCommand.Parameters.Add(paramCategoryID)

Dim dsProducts As New DataSet
cmdProducts.Fill(dsProducts, "tblDataTable")

repList.DataSource = _
dsProducts.Tables("tblDataTable").DefaultView
repList.DataBind()


End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top