1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Rep Power

    Data base connectivity problem in VB.NET

    If there are two forms 1) Main form 2) Sub Form

    In the Main Form there is a button which leads to the sub Form
    The Sub form has got some database connectivity in that..
    Do i have to create the connection in the main form or is it fine if I create it in the sub Form cuz Im getting security exceptions.

    Can someone please help me out??? I appreicate ur help in advance
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Rep Power

    Actually Problem with the data base connectivity

    Actually it is having probblem with data base connectivity

    It says:

    An unhandled exception of type 'System.Security.SecurityException' occurred in Sample.exe

    Can some1 help me out

    herez the code

    Public Class Form1
        Inherits System.Windows.Forms.Form
    #Region " Windows Form Designer generated code "
        Public Sub New()
            'This call is required by the Windows Form Designer.
            'Add any initialization after the InitializeComponent() call
        End Sub
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                End If
            End If
        End Sub
        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer
        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer.  
        'Do not modify it using the code editor.
        Friend WithEvents lblFirstName As System.Windows.Forms.Label
        Friend WithEvents lblLastName As System.Windows.Forms.Label
        Friend WithEvents lblAddress As System.Windows.Forms.Label
        Friend WithEvents txtFirstName As System.Windows.Forms.TextBox
        Friend WithEvents txtLastName As System.Windows.Forms.TextBox
        Friend WithEvents txtAddress As System.Windows.Forms.TextBox
        Friend WithEvents btnSubmit As System.Windows.Forms.Button
        Friend WithEvents odbconSam As System.Data.OleDb.OleDbConnection
        Friend WithEvents odbdaSample As System.Data.OleDb.OleDbDataAdapter
        Friend WithEvents DsSample1 As Sample.dsSample
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.lblFirstName = New System.Windows.Forms.Label()
            Me.lblLastName = New System.Windows.Forms.Label()
            Me.lblAddress = New System.Windows.Forms.Label()
            Me.txtFirstName = New System.Windows.Forms.TextBox()
            Me.txtLastName = New System.Windows.Forms.TextBox()
            Me.txtAddress = New System.Windows.Forms.TextBox()
            Me.btnSubmit = New System.Windows.Forms.Button()
            Me.odbconSam = New System.Data.OleDb.OleDbConnection()
            Me.odbdaSample = New System.Data.OleDb.OleDbDataAdapter()
            Me.DsSample1 = New Sample.dsSample()
            CType(Me.DsSample1, System.ComponentModel.ISupportInitialize).BeginInit()
            Me.lblFirstName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            Me.lblFirstName.Location = New System.Drawing.Point(72, 32)
            Me.lblFirstName.Name = "lblFirstName"
            Me.lblFirstName.Size = New System.Drawing.Size(104, 32)
            Me.lblFirstName.TabIndex = 0
            Me.lblFirstName.Text = "FirstName"
            Me.lblLastName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            Me.lblLastName.Location = New System.Drawing.Point(72, 80)
            Me.lblLastName.Name = "lblLastName"
            Me.lblLastName.Size = New System.Drawing.Size(104, 32)
            Me.lblLastName.TabIndex = 1
            Me.lblLastName.Text = "LastName"
            Me.lblAddress.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
            Me.lblAddress.Location = New System.Drawing.Point(72, 128)
            Me.lblAddress.Name = "lblAddress"
            Me.lblAddress.Size = New System.Drawing.Size(104, 32)
            Me.lblAddress.TabIndex = 2
            Me.lblAddress.Text = "Address:"
            Me.txtFirstName.Location = New System.Drawing.Point(200, 32)
            Me.txtFirstName.Multiline = True
            Me.txtFirstName.Name = "txtFirstName"
            Me.txtFirstName.Size = New System.Drawing.Size(112, 32)
            Me.txtFirstName.TabIndex = 3
            Me.txtFirstName.Text = ""
            Me.txtLastName.Location = New System.Drawing.Point(200, 80)
            Me.txtLastName.Multiline = True
            Me.txtLastName.Name = "txtLastName"
            Me.txtLastName.Size = New System.Drawing.Size(112, 32)
            Me.txtLastName.TabIndex = 4
            Me.txtLastName.Text = ""
            Me.txtAddress.Location = New System.Drawing.Point(200, 128)
            Me.txtAddress.Multiline = True
            Me.txtAddress.Name = "txtAddress"
            Me.txtAddress.Size = New System.Drawing.Size(112, 32)
            Me.txtAddress.TabIndex = 5
            Me.txtAddress.Text = ""
            Me.btnSubmit.Location = New System.Drawing.Point(72, 200)
            Me.btnSubmit.Name = "btnSubmit"
            Me.btnSubmit.Size = New System.Drawing.Size(112, 40)
            Me.btnSubmit.TabIndex = 6
            Me.btnSubmit.Text = "Submit"
            Me.odbconSam.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=Z:\course\" & _
            "Chapter.04\Data\sample.mdb;Mode=Share Deny None;Extended Properties="""";Jet OLEDB" & _
            ":System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Password="""";Je" & _
            "t OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial" & _
            " Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password" & _
            "="""";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet " & _
            "OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repai" & _
            "r=False;Jet OLEDB:SFP=False"
            Me.odbdaSample.TableMappings.AddRange(New System.Data.Common.DataTableMapping() {New System.Data.Common.DataTableMapping("Table", "tblSample", New System.Data.Common.DataColumnMapping() {New System.Data.Common.DataColumnMapping("fldAddress", "fldAddress"), New System.Data.Common.DataColumnMapping("fldFirstName", "fldFirstName"), New System.Data.Common.DataColumnMapping("fldLastName", "fldLastName")})})
            Me.DsSample1.DataSetName = "dsSample"
            Me.DsSample1.Locale = New System.Globalization.CultureInfo("en-US")
            Me.DsSample1.Namespace = "http://www.tempuri.org/dsSample.xsd"
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(584, 469)
            Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnSubmit, Me.txtAddress, Me.txtLastName, Me.txtFirstName, Me.lblAddress, Me.lblLastName, Me.lblFirstName})
            Me.Name = "Form1"
            Me.Text = "Form1"
            CType(Me.DsSample1, System.ComponentModel.ISupportInitialize).EndInit()
        End Sub
    #End Region
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim pbndTemp As Binding, pintRecords As Integer
            pintRecords = odbdaSample.Fill(DsSample1)
            pbndTemp = New Binding("Text", DsSample1, "tblSample.fldFirstName")
            pbndTemp = New Binding("Text", DsSample1, "tblSample.fldLastName")
            pbndTemp = New Binding("Text", DsSample1, "tblSample.Address")
        End Sub
    End Class
    Last edited by lolli; September 30th, 2003 at 01:33 PM.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Rep Power

    Wink you issue is quite vague.....

    Are you using a web app or a win app? I just want to be sure. It sounds like you have a WINFORM app.

    You can make the connectivity from anywhere, depending on how you declare it's method openess. (public, friendly.....)

    Why not put your connectivity in a class of it's own and inhereit it whereever you need it? Or put it in the application level and globally use it? If you are using VS.NET, be sure to test your connection string out first to be sure you will connect properly without errors.

    But as far as the location, it can be anywhere. So I feel your issue is either in your adapter, it's imported classes (ADO vs ADO.NET) or (SQLadapter vs OLEDBadapter).

    Hope it helps!
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Rep Power

    Talking first off, mine was posted before I read your second.....

    OK, first problem... you are using the drag and drop wizard.... I HATE IT. it's nice at first... but it buggers up things.

    try doing this a bit differently, it will be easier for you to see how things are working as well......

    I'm going to show you an SQL SERVER implementation:

    In your imports area (up top):
    Imports System.Data
    Imports System.Data.SqlClient

    IN YOUR DECLARATIONS, try something like this:
    Private SQLconn As String = "data source=SERVERNAME; initial catalog=Northwind;persist security info=True;user id=USERID;password=USERPASS;"

    Once you do both of those, you can consume the SQL service:


    Dim NAVconn As SqlConnection = New SqlConnection(SQLconn)
    Dim NavData_ds As New DataSet

    Dim da_NavData As New SqlDataAdapter("Select * from Categories", NAVconn)
    da_NavData.Fill(NavData_ds, "Categories")


    '*** GETTING DATA INTO A SESSION OBJECT ********************'
    Dim ds_DataSet As New DataSet
    Session("TempData") = ds_DataSet
    Dim copy_NavData As DataTable
    copy_NavData = ws_sql_test.GetData().Tables("Categories").Copy()
    copy_NavData = Nothing
    ws_sql_test = Nothing

    '*** SETTING A DATA VIEW FOR USE BY CONTROLS ********************'
    Dim dv As New DataView(Session("TempData").Tables(0))
    'dv.RowFilter = "CategoryName = 'Humtyfratz'"
    dv.Sort = "CategoryID"


    '*** GETTING NAME ONLY FOR LIST BOUND CONTROL ********************'
    ListBox1.DataSource = dv
    ListBox1.DataMember = "CategoryName"
    ListBox1.DataTextField = "CategoryName"
    'ListBox1.DataValueField = "AliasSeqNumber"

    '*** GETTING NAME ONLY FOR DATA GRID (NOT VIEW) CONTROL ********************'
    DataGrid1.DataSource = Session("TempData")


    I know that is a lot, but maybe it will head off some questions you would have had coming up next!

    Good LUCK!
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Rep Power
    Thanx for ur help

IMN logo majestic logo threadwatch logo seochat tools logo