The OLE DB provider "MSDASQL" for linked server "(null)" reported an error - sql

I'm very very stuck here, help is greatly appreciated.
What am I trying to do?
There is an ASP-page (classic ASP) with a CSV upload that gives the following error:
Microsoft OLE DB Provider for SQL Server error '80040e14'
The OLE DB provider "MSDASQL" for linked server "(null)" reported an error. The provider did not give any information about the error.
/ùùù.stocklist.be/importCSVProcess.asp, line 86
I have created two linked servers:
EXEC master.dbo.sp_addlinkedserver
#server = N'txtsrv'
, #srvproduct=N'Jet 4.0'
, #provider=N'Microsoft Text Driver (*.txt; *.csv)'
, #datasrc=N'D:\WEBSITES\ùùù.stocklist.be\csv\upload'
, #provstr=N'Text'
and
EXEC sp_addlinkedserver
#server = 'Server1',
#srvproduct = '',
#provider = 'MSDASQL',
#datasrc = '
'
When I replace MSDASQL by txtsrv in the following query I get this error:
The OLE DB provider "txtsrv" has not been registered.
This is the code where the insert is done:
If upl.Form("rdbType") = "lot" Then
updFileNameSQL ="insert into cos_lot(lot_vin) " & _
"SELECT vin " & _
"FROM OPENROWSET " & _
"('MSDASQL', " & _
"'Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" & sServerPath & ";', " & _
"'SELECT vin from " & UplFileName & "') " & _
"where not vin IS NULL AND vin collate SQL_Latin1_General_CP1_CI_AS not in (select lot_vin from cos_lot) "
Set updCmd = Server.CreateObject("ADODB.Command")
updCmd.ActiveConnection = MM_COS_STRING
updCmd.CommandText = updFileNameSQL
updCmd.Execute
ElseIf upl.Form("rdbType") = "premie" Then
updFileNameSQL ="INSERT INTO [ùùùSTOCKLIST].[dbo].[COS_ANNEX] " & _
"([annex_type] " & _
",[annex_chassisnr] " & _
",[annex_datum] " & _
",[annex_userid] " & _
",[annex_stockid] " & _
",[annex_commentNL] " & _
",[annex_commentFR] " & _
",[annex_premie] " & _
",[annex_premie_type] " & _
",[annex_consignatie] " & _
",[annex_eindeconsignatie] " & _
",[annex_online] " & _
",[annex_onlinefrom] " & _
",[annex_onlineto] " & _
",[annex_libelle]) " & _
"SELECT 2 " & _
",[VIN] " & _
",Getdate() " & _
", " & Session("user_id") & " " & _
",[STOCK] " & _
",'' " & _
",'' " & _
",Replace([PREMIE],',','.') " & _
",'E' " & _
",Null " & _
",Null " & _
",1 " & _
",cast([ONLINEFROM] as smalldatetime) " & _
",cast([ONLINETO] as smalldatetime) " & _
",[TYPE] " & _
"FROM OPENROWSET " & _
"('MSDASQL', " & _
"'Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=" & sServerPath & ";', " & _
"'SELECT vin,stock,type,premie,onlinefrom,onlineto from " & UplFileName & "') " & _
"WHERE NOT VIN IS NULL "
Set updCmd = Server.CreateObject("ADODB.Command")
updCmd.ActiveConnection = MM_COS_STRING
updCmd.CommandText = updFileNameSQL
updCmd.Execute
End If
at the end: updCmd.Execute I get the above error.
What could I be doing wrong?
Thanks in advance!
PS: server is Win2003 R2 x86

I wonder would it be worth trying a different connection string?
updFileNameSQL ="insert into cos_lot(lot_vin) " & _
"SELECT vin " & _
"FROM OPENROWSET " & _
"('Microsoft.Jet.OLEDB.4.0'," & _
"'Text;HDR=Yes;FMT=Delimited;DATABASE=" & sServerPath & ";'," & _
"'SELECT vin from [" & UplFileName & "]') " & _
"where not vin IS NULL AND vin collate SQL_Latin1_General_CP1_CI_AS " & _
"not in (select lot_vin from cos_lot) "

Related

Having issues with how to use ' or " in sql statement and query using concatrelated function

I have the following code using the ConcatRelated function. the current sql works with 1 where condition but I can't figure out how to get the sql to work with 2 conditions. It works when use it in a query. I get issues and the code does not debug.
ItemsShpdInvSQL = "SELECT InvoiceAllShippedItems.ShipmentID, InvoiceAllShippedItems.ShipType, " _
& "InvoiceAllShippedItems.BillTo, InvoiceAllShippedItems.CustID AS Consignee, " _
& "InvoiceAllShippedItems.PayMethod, InvoiceAllShippedItems.PaidInFull, " _
& "First(InvoiceAllShippedItems.Units) AS Units, " _
& "'Freight Charges - Ref. WR: ' & (ConcatRelated('[WR]'," _
& "'[InvoiceAllShippedItems]','[BillTo] =' & [BillTo])) & " _
& "' - (' & Sum([Chargeable]) & ' ' & [Units] & ' " _
& ") - Number of Pieces: ' & [NoPieces] AS InvDetails, " _
& "Sum(InvoiceAllShippedItems.[# of Pieces]) AS NoPieces, " _
& "Sum(InvoiceAllShippedItems.Chargeable) AS Charge, " _
& "CustRate([custid],[ShipType]) AS CustomerRate, " _
& "IIf(([Charge])<6.1,20/[Charge],[CustomerRate]) AS RateMin " _
& "FROM InvoiceAllShippedItems " _
& "GROUP BY InvoiceAllShippedItems.ShipmentID, " _
& "InvoiceAllShippedItems.ShipType, InvoiceAllShippedItems.BillTo, " _
& "InvoiceAllShippedItems.CustID, InvoiceAllShippedItems.PayMethod, " _
& "InvoiceAllShippedItems.PaidInFull, InvoiceAllShippedItems.Units, " _
& "CustRate([custid],[ShipType]) " _
& "ORDER BY InvoiceAllShippedItems.BillTo;"
'& "CustRate([custid],[ShipType]);"
with this it works in a query but not in the code above:
'concatrelated("[WR]","InvoiceAllShippedItems","[BillTo]&[PayMethod] ='" & [BillTo] & [PayMethod] & "'")

add a row to query in MS-ACCESS SQL

I'm trying to add to the following query:
strSQL = "SELECT fldName, blkName, CDbl(fldValue) " & _
"FROM dbSecurities2 as S " & _
"WHERE " & _
"S.isin='" & Code & "' " & _
"AND " & _
"S.fldName='" & fldName & "' "
A row that makes the sum of the fldValue like:
strSQL = "SELECT fldName, blkName, CDbl(fldValue) " & _
"FROM dbSecurities2 as S " & _
"UNION " & _
"SELECT Sum(fldValue) AS fldValue " & _
"WHERE " & _
"S.isin='" & Code & "' " & _
"AND " & _
"S.fldName='" & fldName & "' "
the error is:
Run -time error '3141'. The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect
I found this is working:
strSQL = "SELECT fldName, blkName, CDbl(fldValue) " & _
"FROM dbSecurities2 as S " & _
"WHERE " & _
"S.isin='" & Code & "' " & _
"AND " & _
"S.fldName='" & fldName & "' " & _
"UNION " & _
"SELECT '' AS fldName, 'Total' AS Total, Sum(CDbl(fldValue)) " & _
"FROM dbSecurities2 AS B " & _
"WHERE " & _
"B.isin='" & Code & "' " & _
"AND " & _
"B.fldName='" & fldName & "' "
This should run as expected:
strSQL = "SELECT fldName, blkName, CDbl(fldValue) " & _
"FROM dbSecurities2 AS S " & _
"WHERE " & _
"S.isin='" & Code & "' " & _
"AND " & _
"S.fldName='" & fldName & "' " & _
"UNION ALL " & _
"SELECT TOP 1 "", "Total", Sum(CDbl(fldValue)) " & _
"FROM dbSecurities2"
If you have Null values, use Nz:
strSQL = "SELECT fldName, blkName, CDbl(Nz(fldValue, 0)) " & _
"FROM dbSecurities2 AS S " & _
"WHERE " & _
"S.isin='" & Code & "' " & _
"AND " & _
"S.fldName='" & fldName & "' " & _
"UNION ALL " & _
"SELECT TOP 1 "", "Total", Sum(CDbl(Nz(fldValue, 0))) " & _
"FROM dbSecurities2"

Why does my Access SQL VBA code jump out of the Sub?

My code is exiting out of the sub on the line that says "CurrentDb.Execute strSQL_Insert_Data". Do you know why this is happening?
Local_Array = Array("dbo_Tape_Capture_Local_tbl", "dbo_Tape_Local_tbl", "dbo_Tape_Memo_Local_tbl")
Server_Array = Array("dbo_Tape_Capture", "dbo_Tape", "dbo_Tape_Memo")
For i = 0 To UBound(Local_Array)
strSQL_Insert_Data = "INSERT INTO [" & Local_Array(i) & "] " & _
"SELECT [" & Server_Array(i) & "].* " & _
"WHERE (LEFT([" & Server_Array(i) & "].header__situs_loan_id," & _
Len([Forms]![Login Page]![CBO_Job_Select_Login]) & ") = " & _
"[Forms]![Login Page]![CBO_Job_Select_Login]);"
CurrentDb.Execute strSQL_Insert_Data
CurrentDb.Close
Next i
--Added Printed out code--
INSERT INTO [dbo_Tape_Capture_Local_tbl] SELECT [dbo_Tape_Capture].*
WHERE (LEFT([dbo_Tape_Capture].header__situs_loan_id,14) = [Forms]![Login Page]![CBO_Job_Select_Login]);
There is missing FROM TableName in your query. Replace TableName with Actual Table Name
strSQL_Insert_Data = "INSERT INTO [" & Local_Array(i) & "] " & _
"SELECT [" & Server_Array(i) & "].* " & _
"FROM [" & Server_Array(i) & "] " & _
"WHERE (LEFT([" & Server_Array(i) & "].header__situs_loan_id," & _
Len([Forms]![Login Page]![CBO_Job_Select_Login]) & ") = " & _
"[Forms]![Login Page]![CBO_Job_Select_Login]);"

ms access 2007 update error run time error 3464, data type mismatch in criteria expression

i cannot update the data, it says that data type mismatch in criteria experession
CurrentDb.Execute "UPDATE PC_Details " & _
" SET Serial_No=" & Me.txtNo & _
", PC_Brand='" & Me.txtBrand & "'" & _
", PC_Model='" & Me.txtModel & "'" & _
", Status='" & Me.txtStatus & "'" & _
", Description='" & Me.txtDesc & "'" & _
", Staff_ID='" & Me.txtID & "'" & _
" WHERE Serial_No=" & Me.txtNo.Tag
Do this to debug:
Dim SQL As String
SQL = "UPDATE PC_Details " & _
" SET Serial_No=" & Me.txtNo & _
", PC_Brand='" & Me.txtBrand & "'" & _
", PC_Model='" & Me.txtModel & "'" & _
", Status='" & Me.txtStatus & "'" & _
", Description='" & Me.txtDesc & "'" & _
", Staff_ID='" & Me.txtID & "'" & _
" WHERE Serial_No=" & Me.txtNo.Tag
Debug.Print SQL
CurrentDb.Execute SQL
Then study the resulting SQL and post it here.
If all values are present, one or more is text but is handled as number or vice versa.

Insert from Two tables to One while duplicates are ignored

I am trying to insert from two MS Access tables into one ms access table.
In one of the two tables there is a column that contains a duplicate value.
What I have at the moment is:
Dim MySQL As String = "INSERT INTO XML_TEST_CASE (" & _
"TCParmId, " & _
"TestCase, " & _
"MessageType, " & _
"FileNo, " & _
"InstructionNo, " & _
"TransactionNo, " & _
"ElementNo, " & _
"MessageSection, " & _
"ElementLevel, " & _
"FullElementPath, " & _
"ElementValue, " & _
"ElementValueNew, " & _
"NameSpace, " & _
"NameSpaceValue, " & _
"Attribute, " & _
"AttributeValue, " & _
"TestCaseDescription) " & _
"SELECT " & _
"P.TCParmId, " & _
"P.TestCase, " & _
"P.MessageType, " & _
"P.FileNo, " & _
"P.InstructionNo, " & _
"P.TransactionNo, " & _
"S.ElementNo, " & _
"S.MessageSection, " & _
"S.ElementLevel, " & _
"S.ElementPath + S.Element, " & _
"S.ElementValue, " & _
"S.ElementValue, " & _
"S.NameSpace, " & _
"S.NameSpaceValue, " & _
"S.Attribute, " & _
"S.AttributeValue, " & _
"P.TestCaseDescription " & _
"FROM XML_TEST_CASE_PARAMETER P, XML_MESSAGE_STRUCTURE S " & _
"WHERE S.MessageType = P.MessageType " & _
"AND P.TestCase = '" & MyTestCase & "' " & _
"AND P.MessageType = '" & MyMessageType & "' " & _
"AND P.FileNo = " & MyFileNo & " " & _
"AND P.InstructionNo = " & MyInstructionNo & " " & _
"AND P.TransactionNo = " & MyTransactionNo & ";"
The problem is that in the XML_MESSAGE_STRUCTURE table it happens that S.ElementNo sometimes appreas more than once which then cuasing that I get also more than one records in my destination table for the specific ElementNo. This I do not want.
Any help is appreaciated.
Rico
Instead of SELECT DISTINCT, you could group by all of the fields except ElementNo. For ElementNo, you would select Max(ElementNo):
Dim MySQL As String = "INSERT INTO XML_TEST_CASE (" & _
"TCParmId, " & _
"TestCase, " & _
"MessageType, " & _
"FileNo, " & _
"InstructionNo, " & _
"TransactionNo, " & _
"ElementNo, " & _
"MessageSection, " & _
...
"SELECT " & _
"P.TCParmId, " & _
"P.TestCase, " & _
"P.MessageType, " & _
"P.FileNo, " & _
"P.InstructionNo, " & _
"P.TransactionNo, " & _
"Max(S.ElementNo), " & _
"S.MessageSection, " & _
...
"FROM XML_TEST_CASE_PARAMETER P, XML_MESSAGE_STRUCTURE S " & _
"WHERE S.MessageType = P.MessageType " & _
"AND P.TestCase = '" & MyTestCase & "' " & _
"AND P.MessageType = '" & MyMessageType & "' " & _
"AND P.FileNo = " & MyFileNo & " " & _
"AND P.InstructionNo = " & MyInstructionNo & " " & _
"AND P.TransactionNo = " & MyTransactionNo & _
"GROUP BY " & _
"P.TCParmId, " & _
"P.TestCase, " & _
"P.MessageType, " & _
"P.FileNo, " & _
"P.InstructionNo, " & _
"P.TransactionNo, " & _
"S.MessageSection, " & _
...
";"