Microsoft ACE OLEDB connection creating filter like use "Excel.Application" - oledb

Can I make filter in created excel?
This is the standard connection string e.g. I create file Excel and save to disk
ConnectionString= "
|Provider=Microsoft.ACE.OLEDB.12.0;
|Data Source="+NameExcel+";
|Extended Properties=""Excel 12.0;HDR=Yes;IMEX=0;""";
Connection = new COMObject("ADODB.Connection");
Connection.Open(ConnectionString);
Command = new COMObject("ADODB.Command");
Command.ActiveConnection = Connection;
Command.CommandType = 1;
TablName= "Mane1";
Command.CommandText = "CREATE TABLE ["+NameTabl+"] ([Vagon] int, [Date op] date,
[Operation] char(255), [Date NSP] date)";
Command.Execute();
but I'd like to set filter on head My table
I have used "Excel.Application" I can do it used it:
Region = Excel.ActiveSheet.Range(Excel.ActiveSheet.Cells(1,1),Excel.ActiveSheet.Cells(1,CountColumn);
But I'm reaquared to use Microsoft.ACE.OLEDB.12.0 without "Excel.Application"

Related

Ms Access 2016 Hashtable cause Automation error

In our old system we were using ms access 2003
Now we move our system to ms access 2016 now we are getting Automation error
when we debug;
msSqlAccessRelations.Add "CurrentUserId", "CurrentUserId"
this line gives an error.
we defined hashtable like this
Dim msSqlAccessRelations As New Hashtable
also mscorlib reference already added.
this code perfectly works on ms access 2003
Dim db As Database
Set db = CurrentDb
Dim rs As ADODB.Recordset
Dim msQry(0) As String
Dim accessQry(0) As String
Dim msSqlAccessRelations As New Hashtable
msQry(0) = "Select * From [IFSDB].[dbo].[Notes] Where ReferNum = " & ReferNum & " AND ReferTypeId = " & ReferTypeId & " " & extraFilter & " Order by NoteID desc"
accessQry(0) = "Select CurrentUserId , CurrentUserPrinted from TblCurrentUser"
msSqlAccessRelations.Add "CurrentUserId", "CurrentUserId"
If GetMSSQLDown = False Then
Set GetNotes = GetDataToDifferentDb(msQry, accessQry, msSqlAccessRelations, "CurrentUserPrinted,Note,NoteID,CurrentUserId,ReferNum,ReferTypeId,AppearOnReport,AppearOnBOLReport,Date,ShowForPickers")
Else
Set GetNotes = rs
End If

vbscript and prncnfg.vbs inside?

I have a vbscript to get some informations about the system printing of a remote computer. I can get all the drivers installed, the default network printer name and all my results are send in a outputfile.
I want to get informations about my default network printer by the prncnfg.vbs from the printer server (driver, location, etc.) and send these informations in my outputfile.
Maybe there is an other way to do that ?
Thanks for any suggestions
So, I start to understand the way to do that. But something doesn't work.
First I need to read a file and remove 10 caracters to create my variable, this process works very well:
'Read C:\Temp\DefaultPrinter
Dim shortDefaultPrinter
If objFSO.FileExists("\"& strComputer &"\c$\Temp\DefaultPrinter.txt") then
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("\"& strComputer &"\c$\Temp\DefaultPrinter.txt",1)
DefaultPrinter = objFileToRead.ReadAll()
'remove text \vangogh\
shortDefaultPrinter = Right(DefaultPrinter, Len(DefaultPrinter) - 10)
'MsgBox(shortDefaultPrinter)
objFileToRead.Close
Set objFileToRead = Nothing
Second I want to use my variable shortDefaultPrinter for my query to find the location of my printer:
'Select DefaultPrinter and show location
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName, Location from " _
& " 'LDAP://DC=huge,DC=ad,DC=hcuge,DC=ch' where objectClass='printQueue' and printerName='" & shortDefaultPrinter & "' "
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
PrinterLocation = objRecordSet.Fields("Location").Value
MsgBox(PrinterLocation)
objRecordSet.MoveNext
Loop
MsgBox doesn't open, but if I write the name of the printer in place of " & shortDefaultPrinter & ", ex dmed-i714, the process works.
Here I am. If anyone has a suggestion it would be appreciate.

How to filter Flat File Source using script component

I have the following scenario:
I have thousands of text files with the below format.The column names are written in separate lines where as the row values are delimited by Pipe(|).
START-OF-FILE
PROGRAMNAME=getdata
DATEFORMAT=yyyymmdd
#Some Text
#Some Text
#Some Text
#Some Text
#Some Text
START-OF-FIELDS
Field1
Field2
Field3
------
FieldN
END-OF-FIELDS
TIMESTARTED=Tue May 12 16:04:42 JST 2015
START-OF-DATA
Field1Value|Field2value|Field3Value|...|Field N Value
Field1Value|Field2value|Field3Value|...|Field N Value
------|...........|----|-------
END-OF-DATA
DATARECORDS=30747
TIMEFINISHED=Tue May 12 16:11:53 JST 2015
END-OF-FILE
Now I have a corresponding SQL Server table, where I can easily load the data as destination.
Since I am new to SSIS, having trouble as to how to write the Script Component so that I can filter the Source Text files and easily load into sql server table.
Thanks in advance!
There are a few ways to do it. If the format of the files are constant, there are some useful properties of the flat file connection manager editor. For example, you can add a new flat file connection into the connection managers. There are some properties such as "Rows to skip" for the above file, you could set this to 18. Then it would start at the columns line with the "|".
Another property of the flat file connection manager that may be useful is that if you open the flat file connection manager, and then click on columns in the side menu, you can set the column delimter to the pipe "|"
But if the format of the file will change, e.g. variable number of header rows, you can use a script task to remove any non-piped rows. e.g. the header and footer.
For example, you can add a method such as file.readalllines and then edit or remove the lines as needed then save the file.
Info about that method is here:
https://msdn.microsoft.com/en-us/library/s2tte0y1%28v=vs.110%29.aspx
e.g. to remove last line in script task
string[] lines = File.ReadAllLines( "input.txt" );
StringBuilder sb = new StringBuilder();
int count = lines.Length - 1; // all except last line
for (int i = 0; i < count; i++)
{
sb.AppendLine(lines[i]);
}
File.WriteAllText("output.txt", sb.ToString());
USE Below VB Script in your SSIS SCript Component Task as source
enter code here
Imports System
Imports System.Data
Imports System.Math
Imports System.IO
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
<Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute()> _
<CLSCompliant(False)> _
Public Class ScriptMain
Inherits UserComponent
'Private strSourceDirectory As String
'Private strSourceFileName As String
Private strSourceSystem As String
Private strSourceSubSystem As String
Private dtBusinessDate As Date
Public Overrides Sub PreExecute()
MyBase.PreExecute()
'
' Add your code here for preprocessing or remove if not needed
''
End Sub
Public Overrides Sub PostExecute()
MyBase.PostExecute()
'
' Add your code here for postprocessing or remove if not needed
' You can set read/write variables here, for example:
Dim strSourceDirectory As String = Me.Variables.GLOBALSourceDirectory.ToString()
Dim strSourceFileName As String = Me.Variables.GLOBALSourceFileName.ToString()
'Dim strSourceSystem As String = Me.Variables.GLOBALSourceSystem.ToString()
'Dim strSourceSubSystem As String = Me.Variables.GLOBALSourceSubSystem.ToString()
'Dim dtBusinessDate As Date = Me.Variables.GLOBALBusinessDate.Date
End Sub
Public Overrides Sub CreateNewOutputRows()
'
' Add rows by calling the AddRow method on the member variable named "<Output Name>Buffer".
' For example, call MyOutputBuffer.AddRow() if your output was named "MyOutput".
'
Dim sr As System.IO.StreamReader
Dim strSourceDirectory As String = Me.Variables.GLOBALSourceDirectory.ToString()
Dim strSourceFileName As String = Me.Variables.GLOBALSourceFileName.ToString()
'Dim strSourceSystem As String = Me.Variables.GLOBALSourceSystem.ToString()
'Dim strSourceSubSystem As String = Me.Variables.GLOBALSourceSubSystem.ToString()
'Dim dtBusinessDate As Date = Me.Variables.GLOBALBusinessDate.Date
'sr = New System.IO.StreamReader("C:\QRM_SourceFiles\BBG_BONDS_OUTPUT_YYYYMMDD.txt")
sr = New System.IO.StreamReader(strSourceDirectory & strSourceFileName)
Dim lineIndex As Integer = 0
While (Not sr.EndOfStream)
Dim line As String = sr.ReadLine()
If (lineIndex <> 0) Then 'remove header row
Dim columnArray As String() = line.Split(Convert.ToChar("|"))
If (columnArray.Length > 1) Then
Output0Buffer.AddRow()
Output0Buffer.Col0 = columnArray(0).ToString()
Output0Buffer.Col3 = columnArray(3).ToString()
Output0Buffer.Col4 = columnArray(4).ToString()
Output0Buffer.Col5 = columnArray(5).ToString()
Output0Buffer.Col6 = columnArray(6).ToString()
Output0Buffer.Col7 = columnArray(7).ToString()
Output0Buffer.Col8 = columnArray(8).ToString()
Output0Buffer.Col9 = columnArray(9).ToString()
Output0Buffer.Col10 = columnArray(10).ToString()
Output0Buffer.Col11 = columnArray(11).ToString()
Output0Buffer.Col12 = columnArray(12).ToString()
Output0Buffer.Col13 = columnArray(13).ToString()
Output0Buffer.Col14 = columnArray(14).ToString()
Output0Buffer.Col15 = columnArray(15).ToString()
Output0Buffer.Col16 = columnArray(16).ToString()
Output0Buffer.Col17 = columnArray(17).ToString()
Output0Buffer.Col18 = columnArray(18).ToString()
Output0Buffer.Col19 = columnArray(19).ToString()
Output0Buffer.Col20 = columnArray(20).ToString()
Output0Buffer.Col21 = columnArray(21).ToString()
Output0Buffer.Col22 = columnArray(22).ToString()
Output0Buffer.Col23 = columnArray(23).ToString()
Output0Buffer.Col24 = columnArray(24).ToString()
End If
End If
lineIndex = lineIndex + 1
End While
sr.Close()
End Sub
End Class
Code End

LSXLC ODBC Stored Procedure

I'm trying to connect to an Oracle RDB database using LSXLC (ODBC Connector).
But when it comes to stored procedures I'm having a hard time getting it to work.
The code below always results in "Error: Parameter name not supplied: fnl_date, Connector 'odbc2', Method -Call-". The error is triggered on "count = connection.Call(input, 1, result)"
Can anyone tell me what I'm doing wrong?
Public Function testLsxlcProc()
On Error GoTo handleError
Dim connection As LCConnection("odbc2")
connection.Server = "source"
connection.Userid = "userid"
connection.Password = "password"
connection.procedure = "proc_name"
connection.Connect
If connection.IsConnected Then
Dim input As New LCFieldList()
Dim result As New LCFieldList()
Dim break As LCField
Set break = input.Append("fnl_date", LCTYPE_TEXT)
break.Text = "2014-07-01"
Dim agrNo As LCField
Set agrNo = input.Append("fnl_agreement_no", LCTYPE_TEXT)
agrNo.Text = "123456"
Dim curr As LCField
Set curr = input.Append("fnl_currency_code", LCTYPE_TEXT)
curr.Text = "SEK"
Dim stock As LCField
Set stock = input.Append("fnl_stock_id", LCTYPE_TEXT)
stock.Text = "01"
connection.Fieldnames = "status, value"
Dim count As Integer
count = connection.Call(input, 1, result)
Call logger.debug("Count: " & count)
Else
Error 2000, "Unable to connect to database."
End If
handleExit:
connection.Disconnect
Exit Function
handleError:
On Error Resume Next
Call logger.error(Nothing)
Resume handleExit
End Function
Thanks in advance!
I had made a stupid mistake and had a mismatch between the name of the input parameter in Domino and the name of the input parameter in the stored procedure.
Make sure all names match up and there shouldn't be a problem.
Stored-Procedure "mylib.MyStoredProc" wird aufgerufen ...
LcSession.Status = 12325: LC-Error: errCallStoredProc 12325 (Error: Parameter name not supplied: P_S651_AC, Connector 'odbc2', Method -Call-)
Solution: changed "mylib" into "MYLIB" and all was well.
Check not only Parameter-Names, but also the Search-Path.

Classic ASP - ADO execute Stored Procedure passing in parameters

I am needing to pass parameters into a stored procedure with Classic ASP. I do see some people using the Command object and others NOT using it.
My sproc params are like this:
#RECORD_NUMBER decimal(18,0),
#ErrorType nvarchar(100),
#INSURANCE_CODE smallint,
#CompanyId int,
#INS_ID_NUM nchar(22)
Then I'm trying to do this:
Dim conn, rsSet,rsString, cmd
Dim RN,ET,IC,CI,IIN
RN = Request.Form("Record_Number")
ET = Request.Form("ErrorType")
IC = Request.Form("INSURANCE_CODE")
CI = Request.Form("CompanyID")
IIN = Request.Form("INS_ID_NUM")
set conn = server.CreateObject("adodb.connection")
set rsSet = Server.CreateObject ("ADODB.Recordset")
conn.Open Application("conMestamed_Utilities_ConnectionString")
rs_string = "apUpdateBill " & RN &",'" & ET & "'," & IC & "," & CI & ",'" & IIN & "'"
rsSet.Open rsString, conn, adOpenForwardOnly,, adCmdText
(I don't need a Recordset, i'm just trying to get it to send in data)
Error:
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I have tried Command stuff and I get "precision" errors
Do I "have" to use command object?
e.g.
Set cmd = Server.CreateObject("ADODB.Command")
'Set cmd.ActiveConnection = conn
'cmd.CommandText = "apUpdateBill"
'cmd.CommandType = adCmdStoredProc
'Cmd.Parameters.append Cmd.createParameter("#Record_Number", adDecimal, adParamInput, 18)
'Cmd.Parameters("#Record_Number").Precision = 0
'Cmd.Parameters("#Record_Number").value = Request.Form("Record_Number")
Here is how you would do it, you won't need to create a recordset object since it is an update stored procedure:
'Set the connection
'...............
'Set the command
DIM cmd
SET cmd = Server.CreateObject("ADODB.Command")
SET cmd.ActiveConnection = Conn
'Prepare the stored procedure
cmd.CommandText = "apUpdateBill"
cmd.CommandType = 4 'adCmdStoredProc
cmd.Parameters("#RECORD_NUMBER") = Request.Form("Record_Number")
cmd.Parameters("#ErrorType") = Request.Form("ErrorType")
cmd.Parameters("#INSURANCE_CODE") = Request.Form("INSURANCE_CODE")
cmd.Parameters("#CompanyId") = Request.Form("CompanyID")
cmd.Parameters("#INS_ID_NUM") = Request.Form("INS_ID_NUM")
'Execute the stored procedure
'This returns recordset but you dont need it
cmd.Execute
Conn.Close
SET Conn = Nothing

Resources