Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Opening database connection

Opening database connection

Scheduled Pinned Locked Moved Visual Basic
databasecsharphelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johnjsm
    wrote on last edited by
    #1

    Hi, I have the following code which I converted fro c#. Any time I run it I get an error at the con.open() This is the error An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. Here is the code Private Sub LookupDB(ByVal PartNum As String) Dim ConnectString As String = "user id=****;password=****;initial catalog=eLibrarian;data source=" & "*******" Dim con As SqlConnection = New SqlConnection(ConnectString) Dim cmd As SqlCommand = New SqlCommand("pGetSWEETFileAttributes", con) cmd.CommandType = CommandType.StoredProcedure ' ' Initialise parameters to database stored procedure: ' ' 1. Input Parameter representing Part Number ' Dim param As SqlParameter = New SqlParameter("@inparam_ElementID", SqlDbType.VarChar, 50) param.Direction = ParameterDirection.Input param.Value = PartNum cmd.Parameters.Add(param) ' ' Read from database ' con.Open() Dim reader As SqlDataReader = cmd.ExecuteReader() 'ExecuteNonQuery(); Dim record_count As Integer = 0 While reader.Read() txtSize.Text = reader("FileSize").ToString() txtMD5.Text = reader("MD5Checksum").ToString() record_count = record_count + 1 End While reader.Close() con.Close() If record_count = 0 Then Throw New Exception("Part number " + PartNum + " not found in dataMyBase. Please enter the filesize and MD5 checksum") End If End Sub

    C 1 Reply Last reply
    0
    • J johnjsm

      Hi, I have the following code which I converted fro c#. Any time I run it I get an error at the con.open() This is the error An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. Here is the code Private Sub LookupDB(ByVal PartNum As String) Dim ConnectString As String = "user id=****;password=****;initial catalog=eLibrarian;data source=" & "*******" Dim con As SqlConnection = New SqlConnection(ConnectString) Dim cmd As SqlCommand = New SqlCommand("pGetSWEETFileAttributes", con) cmd.CommandType = CommandType.StoredProcedure ' ' Initialise parameters to database stored procedure: ' ' 1. Input Parameter representing Part Number ' Dim param As SqlParameter = New SqlParameter("@inparam_ElementID", SqlDbType.VarChar, 50) param.Direction = ParameterDirection.Input param.Value = PartNum cmd.Parameters.Add(param) ' ' Read from database ' con.Open() Dim reader As SqlDataReader = cmd.ExecuteReader() 'ExecuteNonQuery(); Dim record_count As Integer = 0 While reader.Read() txtSize.Text = reader("FileSize").ToString() txtMD5.Text = reader("MD5Checksum").ToString() record_count = record_count + 1 End While reader.Close() con.Close() If record_count = 0 Then Throw New Exception("Part number " + PartNum + " not found in dataMyBase. Please enter the filesize and MD5 checksum") End If End Sub

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      johnjsm wrote:

      Dim ConnectString As String = "user id=****;password=****;initial catalog=eLibrarian;data source=" & "*******"

      I assume this is not the actual code, you changed it to post it ?

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups