Καλησπέρα,
προσπαθώ να ενημερώσω με στοιχεία της βάσης ένα DropDownList1
στη φόρτωση της σελίδας καλώ την fill_dropdownlist
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
fill_dropdownlist()
Me.DropDownList1.Enabled = True
End If
End Sub
Στη διαδικασία fill_dropdownlist εμφανίζεται error σύνδεσης με τη βάση στην εντολή myconnection.Open()
- το μήνυμα λάθους είναι An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
O ίδιος κώδικας στο framework 1.1 μου δούλευαι ενώ τώρα στο aspnet2 δεν λειτουργεί. Τι μπορεί λάθος να υπάρχει????
Ευχαριστώ εκ των προτέρων
Private Sub fill_dropdownlist()
Dim myconnection As New SqlConnection("server=101.22.22.22;initial catalog=katalogos;user id=myuserid;password=mypassword;")
Dim da As New SqlDataAdapter("SELECT * FROM pinakas_bashs", myconnection)
Dim dt As New DataTable
myconnection.Open()
da.Fill(dt)
' Store the DataTable in a Session variable.
Session(
"TitlesDataTable") = dt
' Manually fill the Items collection of the ddlTitles control.
Dim dr As DataRow
Me.DropDownList1.Items.Clear()
For Each dr In dt.Rows
Me.DropDownList1.Items.Add(dr("last_name").ToString )
Next
DropDownList1.SelectedIndex = 0
' Prepare the Titles variable for binding
Titles = dt.Rows(0)
' Bind all controls.
Me.DataBind()
myconnection.Close()
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
' Retrieve the DataTable object from the session variable.
Dim dt As DataTable = DirectCast(Session("TitlesDataTable"), DataTable)
' Prepare the Titles variable and do the data binding.
Titles = dt.Rows(
Me.DropDownList1.SelectedIndex)
Me.DataBind()
End Sub