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. Error Message

Error Message

Scheduled Pinned Locked Moved Visual Basic
databasehelpquestionannouncement
4 Posts 4 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
    jds1207
    wrote on last edited by
    #1

    I am working on a import program that will import and update paradox file info in a SQL db. When I run my program I get this error: Cannot open database requested in login 'RAM'. Login fails. Here is the code for the function: Public Function ProductExist(ByVal PartNumber As String, ByVal SourceCode As String) As DataTable Dim con As New OleDbConnection Dim cmd As New OleDbCommand Dim dt As New DataTable Dim da As New OleDbDataAdapter 'Tell the connection object where the database is. con.ConnectionString = "Provider=SQLOLEDB;Data Source=****,1433;Initial Catalog=RAM;User ID=****;Password=****;" 'The command object needs to know which database it's connected to. cmd.Connection = con 'The SQL command you want to perform cmd.CommandText = "SELECT ItemPartNumber, ItemSourceCode FROM Item_JS WHERE ItemPartNumber = '" & Trim(PartNumber) & "' AND " & "ItemSourceCode = '" & Trim(SourceCode) & "'" 'Tell the DataAdapter which command object we're using. da.SelectCommand = cmd 'Finally we instruct the DataAdapter to fill the DataTable da.Fill(dt) Return dt End Function The error occurs on the line da.Fill(dt). Any Ideas? jds1207

    C P J 3 Replies Last reply
    0
    • J jds1207

      I am working on a import program that will import and update paradox file info in a SQL db. When I run my program I get this error: Cannot open database requested in login 'RAM'. Login fails. Here is the code for the function: Public Function ProductExist(ByVal PartNumber As String, ByVal SourceCode As String) As DataTable Dim con As New OleDbConnection Dim cmd As New OleDbCommand Dim dt As New DataTable Dim da As New OleDbDataAdapter 'Tell the connection object where the database is. con.ConnectionString = "Provider=SQLOLEDB;Data Source=****,1433;Initial Catalog=RAM;User ID=****;Password=****;" 'The command object needs to know which database it's connected to. cmd.Connection = con 'The SQL command you want to perform cmd.CommandText = "SELECT ItemPartNumber, ItemSourceCode FROM Item_JS WHERE ItemPartNumber = '" & Trim(PartNumber) & "' AND " & "ItemSourceCode = '" & Trim(SourceCode) & "'" 'Tell the DataAdapter which command object we're using. da.SelectCommand = cmd 'Finally we instruct the DataAdapter to fill the DataTable da.Fill(dt) Return dt End Function The error occurs on the line da.Fill(dt). Any Ideas? jds1207

      C Offline
      C Offline
      codemunkeh
      wrote on last edited by
      #2

      I'm not a database guy, although it looks like DT is a null reference when you use it. However, if "da.Fill(dt)" puts da into dt, then my theory falls apart, and could then be that da is not the same type as dt. Perhaps you could check if the connection/command is being loaded correctly by adding breakpoints to each line (remembering that breakpoints come before the line is executed). edit: Apologies. Just looked at it in a bit more depth. Ignore the null reference part. It seems I'm reading the lines wrongly, when I should read it like DirectX's CurrentParameters.


      Need Another Seven Acronyms...
      Confused? You will be...

      1 Reply Last reply
      0
      • J jds1207

        I am working on a import program that will import and update paradox file info in a SQL db. When I run my program I get this error: Cannot open database requested in login 'RAM'. Login fails. Here is the code for the function: Public Function ProductExist(ByVal PartNumber As String, ByVal SourceCode As String) As DataTable Dim con As New OleDbConnection Dim cmd As New OleDbCommand Dim dt As New DataTable Dim da As New OleDbDataAdapter 'Tell the connection object where the database is. con.ConnectionString = "Provider=SQLOLEDB;Data Source=****,1433;Initial Catalog=RAM;User ID=****;Password=****;" 'The command object needs to know which database it's connected to. cmd.Connection = con 'The SQL command you want to perform cmd.CommandText = "SELECT ItemPartNumber, ItemSourceCode FROM Item_JS WHERE ItemPartNumber = '" & Trim(PartNumber) & "' AND " & "ItemSourceCode = '" & Trim(SourceCode) & "'" 'Tell the DataAdapter which command object we're using. da.SelectCommand = cmd 'Finally we instruct the DataAdapter to fill the DataTable da.Fill(dt) Return dt End Function The error occurs on the line da.Fill(dt). Any Ideas? jds1207

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        Can you access the database by other means? I don't know much about Paradox, but it sounds like the code cannot find it or the login credentials could be wrong...

        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        1 Reply Last reply
        0
        • J jds1207

          I am working on a import program that will import and update paradox file info in a SQL db. When I run my program I get this error: Cannot open database requested in login 'RAM'. Login fails. Here is the code for the function: Public Function ProductExist(ByVal PartNumber As String, ByVal SourceCode As String) As DataTable Dim con As New OleDbConnection Dim cmd As New OleDbCommand Dim dt As New DataTable Dim da As New OleDbDataAdapter 'Tell the connection object where the database is. con.ConnectionString = "Provider=SQLOLEDB;Data Source=****,1433;Initial Catalog=RAM;User ID=****;Password=****;" 'The command object needs to know which database it's connected to. cmd.Connection = con 'The SQL command you want to perform cmd.CommandText = "SELECT ItemPartNumber, ItemSourceCode FROM Item_JS WHERE ItemPartNumber = '" & Trim(PartNumber) & "' AND " & "ItemSourceCode = '" & Trim(SourceCode) & "'" 'Tell the DataAdapter which command object we're using. da.SelectCommand = cmd 'Finally we instruct the DataAdapter to fill the DataTable da.Fill(dt) Return dt End Function The error occurs on the line da.Fill(dt). Any Ideas? jds1207

          J Offline
          J Offline
          Johan Hakkesteegt
          wrote on last edited by
          #4

          The error is thrown simply because nowhere in your code do you actually connect to the database.

          jds1207 wrote:

          cmd.Connection = con

          You tell the DataAdapter to use this connection, but not to actually open it. If you want you can try to adapt this function to your needs: Public Function OpenConnection(ByVal conn As SqlConnection, Optional ByVal db As String = "") As Boolean Try If conn.State = ConnectionState.Closed Then conn.Open() If conn.State = ConnectionState.Broken Then conn.Close() conn.Open() If db <> "" Then conn.ChangeDatabase(db) End If If conn.State <> ConnectionState.Open Then OpenConnection = False Else OpenConnection = True Catch Ex As Exception MsgBox(Ex.Message & "happened in: public function OpenConnection") End Try End Function just call it before .Fill. Good luck, Johan

          My advice is free, and you may get what you paid for.

          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