Error Message
-
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 -
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? jds1207I'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... -
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? jds1207Can 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
-
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? jds1207The 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, JohanMy advice is free, and you may get what you paid for.