Results 1 to 17 of 17

Thread: ADO.NET Can't Open Database File

Threaded View

  1. #1

    Thread Starter
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    ADO.NET Can't Open Database File

    Hey guys, long time no see. I decided to play around with SQL using VB.Net with ADO.Net, and for some reason I just can't seem to connect to the database file. I used Tools > Connect to Database, and linked the file with that, which is an accdb file from Access. Didn't change anything really afterwards. And then I ran this code:

    vb.net Code:
    1. Option Explicit On
    2. Option Strict On
    3. Imports System.Data.SqlClient
    4.  
    5. Public Class Form1
    6.     Private myConn As SqlConnection
    7.     Private myCmd As SqlCommand
    8.     Private myReader As SqlDataReader
    9.     Private results As String
    10.  
    11.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    12.         myConn = New SqlConnection("Data Source = Database1")
    13.  
    14.         'Open the connection.
    15.         myConn.Open()
    16.     End Sub
    17.  
    18.     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    19.         'Create a Command object.
    20.         myCmd = myConn.CreateCommand
    21.         myCmd.CommandText = "SELECT * FROM Table1 WHERE ID = " & TextBox1.Text
    22.         myReader = myCmd.ExecuteReader()
    23.         results = results & myReader.GetString(0) & vbTab & myReader.GetString(1)
    24.         Label1.Text = results
    25.     End Sub
    26. End Class

    As a result, I get an unhandled exception. I even tried using an mdb file, and it still fails. Even tried adding "Initial Catalog=Database1;Integrated Security=True" for the myConn connection, and nothing worked. Anyone got any bright ideas? Thanks in advance.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width