Logparser not work in C# - c#

Error parsing query: The specified FROM-ENTITY "<1>" is invalid [The filename, directory name, or volume label syntax is incorrect.]
<1> is working when use in sql in Log Parser 2.2, the folder is exist.
Query is working if i following article - LogParser DataProvider for ADO.NE
try
{
ILogRecord rowLP = null;
ILogRecordset rsLP = null;
LogQueryClass logQuery = new LogQueryClass();
COMW3CInputContextClass comW3CInputContext = new COMW3CInputContextClass();
string strSQL = #"SELECT " +
#"COUNT(*) AS [Requests], " +
#"DIV(DIV(SUM(cs-bytes), 1024), 1024) AS [MBytes received], " +
#"DIV(DIV(SUM(sc-bytes), 1024), 1024) AS [MBytes sent], " +
#"c-ip AS [IP Address], cs(User-Agent) AS [User agent], " +
#"MAX(date) AS [Last visit] " +
#"FROM <1> " +
#"GROUP BY [IP Address], [User agent] " +
#"ORDER BY [Requests] DESC";
// run the query against W3C log
rsLP = logQuery.Execute(strSQL, comW3CInputContext);
rowLP = rsLP.getRecord();
}
catch (System.Runtime.InteropServices.COMException exc)
{
Console.WriteLine("Unexpected error: " + exc.Message);
}

The <1> "magic shortcut" only works with the IISW3C input format, which is the format that parses the W3C log files generated by IIS. In your code, you are using the W3C input format, which parses generic W3C-formatted logs and thus knows nothing about <1>.

I found they is not working by follow this http://www.codeproject.com/Articles/13504/Simple-log-parsing-using-MS-Log-Parser-2-2-in-C-NE which is the line
COMW3CInputContextClass comW3CInputContext = new COMW3CInputContextClass();
rsLP = logQuery.Execute(strSQL, comW3CInputContext);
By make change as below than the query can be work
rsLP = logQuery.Execute(strSQL, null);

Related

"sqlcmd.exe -S Instance USE ..." work in command line, but I can't move it to c # process

I am trying move this command to C# Process:
SQLCMD.EXE -S InstanceName
USE [master]
GO
CREATE DATABASE [Ek] ON
( FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\Ek_Primary.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\Ek_Primary.ldf' )
FOR ATTACH ;
GO
EXIT
I have:
try
{
Process p = CreateProcess();
p.StartInfo.FileName = #"C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\SQLCMD.EXE";
p.StartInfo.Arguments = "-S InstanceName" + "\n" +
"USE [master]" + "\n" +
"GO" + "\n" +
"CREATE DATABASE [Ek] ON" + "\n" +
"( FILENAME = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL15.MSSQLSERVER\\MSSQL\\DATA\\Ek_Primary.mdf' )," + "\n" +
"( FILENAME = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL15.MSSQLSERVER\\MSSQL\\DATA\\Ek_Primary.ldf' )" + "\n" +
"FOR ATTACH ;" + "\n" +
"GO" + "\n" +
"EXIT" + "\n";
Console.WriteLine(p.StartInfo.Arguments);
p.Start();
var output = p.StandardOutput.ReadToEnd();
var err = p.StandardError.ReadToEnd();
Console.WriteLine("O: " + output);
Console.WriteLine("E: " + err);
}
catch (Exception e) { Console.WriteLine(e.Message); ; }
It return err = Unexpected argument. Enter '-?' for help.
I was trying set FileName on cmd.exe and move path to Arguments. But it waits forever for a response and does not exit p.StandardOutput.ReadToEnd ();
I was trying send each line of code individually, but also without success.
And I trying with /C on start p.StartInfo.Argument but it does not change anything.
Thanks to Selvin suggestion. I made it by:
string sqlConnectionString = #"Integrated Security=SSPI;Persist Security Info=False;Data Source=InstanceName";
string script = File.ReadAllText(#"../../sql.sql");
Microsoft.Data.SqlClient.SqlConnection conn = new Microsoft.Data.SqlClient.SqlConnection(sqlConnectionString);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.ExecuteNonQuery(script);
where in sql.sql I added all my sql line.

Value assigned more than once in single assignment

I made script task that's downloading and saving on disk two spreadsheets from Google Drive using file ID and prepared URL address.
This is main() from my C# code, there are no things outside of it:
public void Main()
{
string m_FileId = Dts.Variables["User::varFileId"].Value.ToString();
string m_RemoteUrl = "https://docs.google.com/spreadsheets/d/" + m_FileId + "/export?format=xlsx";
string m_FilePath = null;
WebClient client = new WebClient();
try
{
m_FilePath = Dts.Variables["User::varFilePath"].Value.ToString() + Dts.Variables["User::varFileName"].Value.ToString();
client.DownloadFile(new System.Uri(m_RemoteUrl), m_FilePath);
m_FilePath = "";
m_FileId = Dts.Variables["User::varFileId2"].Value.ToString();
m_RemoteUrl = "https://docs.google.com/spreadsheets/d/" + m_FileId + "/export?format=xlsx";
m_FilePath = Dts.Variables["User::varFilePath"].Value.ToString() + Dts.Variables["User::varFileName2"].Value.ToString();
client.DownloadFile(new System.Uri(m_RemoteUrl), m_FilePath);
}
catch(Exception e)
{
Dts.Events.FireError(0, "FileDownload", e.Message
+ "\r" + e.StackTrace
+ " \rUrl: " + m_RemoteUrl
+ " \rFilePath: " + m_FilePath
+ " \rPath: " + Dts.Variables["User::varFilePath"].Value.ToString()
+ " \rFileName2: " + Dts.Variables["User::varFileName2"].Value.ToString()
, string.Empty, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Problem occurs exactly on every second time I run this code and I don't know how to get rid of it. There's just exception in my script task. I'm printing all variables that are used in this code, and as you can see there's something wrong with m_FilePath, it's like multiplied despite of being printed just once.
[FileDownload] Error: An exception occurred during a WebClient request.
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at ST_84b63d1593dd449886eb2b32dff40b2d.ScriptMain.Main()
Url: https://docs.google.com/spreadsheets/d/----------/export?format=xlsx
FilePath: C:\Google Drive extract\ga_manual_cost_file.xlsxC:\Google Drive extract\ga_manual_cost_file.xlsx
Path: C:\Google Drive extract\ga_manual_cost_file.xlsx
FileName2: ga_manual_cost_file.xlsx
SSIS variables that I'm using are ReadOnly, and are used only in this script task(I tried running only this part of control flow), and their values are as follows:

OrientDB Query works sometimes and at other times throws FormatException

I'm having a problem with this query below. I'm connecting to OrientDB using the C# driver and running the query in my c# code. All this code is in a loop and the queries in the try block works for a number of iterations and afterwards fails throwing a FormatException. At the point it fails I copy out the query and run it in the orientDB web interface and it returns the expect records so I'm sure it's not the input. So I'm so confused as to why it succeeds sometimes and fails at other times even when the input string is correct. Has anyone encountered a similar problem? Someone please help.
string origin = route[i].Trim();
string destination = route[i + 1].Trim();
List<ODocument> document = new List<ODocument>();
try
{
document = database.Query("select from (traverse out_Connects from " + origin + ") where in = " + destination);
//document = database.Query("select from Connects where (out = " + origin + " and in = " + destination + ")");
}
catch (Exception e)
{
//document = database.Query("select from Connects where (out = " + origin + " and in = " + destination + ")");
}

Remove file present on Linux server

Trying to run sudo command with user who has all the priviledges, but something is wrong in my code .
I am trying to remove a file present on the remote server via C# code. It says : The name 'pass' does not exist in the current context.:
My Code :
SshExec sshExec = new SshExec("sj1slm612", "karansha");
sshExec.Password = "pass";
sshExec.Connect();
//Removing config files from sj1slm612 server
string remove_config_file_express = "echo " + "'" + pass + "'" + "| sudo -S -u wtsnqa rm " + "/apps/instances/express_13000/configuration/standalone-full.xml";
string output_express = sshExec.RunCommand(remove_config_file_express);
Console.WriteLine("All config files removed");
Console.ReadLine();
the compiler is indeed correct. you reference a variable called pass which you probably meant to be the string "pass"
string remove_config_file_express = "echo " + "'" + pass + "'" + "| sudo -S -u wtsnqa rm " + "/apps/instances/express_13000/configuration/standalone-full.xml";
Use tamir Library next code.
public static bool BorrarArchivo(string rutaRemota)
{
try
{
SshExec comando = new SshExec(Servidor, Usuario);
comando.Password = Password;
comando.Connect();
string paso = comando.RunCommand("rm " + rutaRemota);
comando.Close();
return true;
}
catch (Exception ex)
{
mErrorSFTP = ex.Message;
return false;
}
}

Exchange Server Error: The remote server returned an error: (440) Login Timeout

I'm creating a window based program to retrieve emails in Exchange Server 2003 using webDAV.
im getting the error on loResponse = (HttpWebResponse)loRequest.GetResponse();
Here's the code:
lsRootUri = p_strServer + "/Exchange//" + p_strAlias + "//" + p_strInboxURL + "//";
lsQuery = "<?xml version=\"1.0\"?>"
+ "<D:searchrequest xmlns:D = \"DAV:\" xmlns:m=\"urn:schemas:httpmail:\">"
+ "<D:sql>SELECT \"urn:schemas:httpmail:hasattachment\", \"DAV:displayname\", "
+ "\"urn:schemas:httpmail:from\", \"urn:schemas:httpmail:subject\", "
+ "\"urn:schemas:httpmail:htmldescription\" FROM \"" + lsRootUri
+ "\" WHERE \"DAV:ishidden\" = false "
+ "AND \"DAV:isfolder\" = false "
+ "AND \"urn:schemas:httpmail:hasattachment\" = true "
+ "AND \"urn:schemas:httpmail:read\" = false"
+ "</D:sql></D:searchrequest>";
loRequest = (HttpWebRequest)WebRequest.Create(lsRootUri);
loRequest.Credentials = new NetworkCredential(p_strUserName, p_strPassword);
loRequest.Method = "SEARCH";
laBytes = System.Text.Encoding.UTF8.GetBytes(lsQuery);
loRequest.ContentLength = laBytes.Length;
loRequestStream = loRequest.GetRequestStream();
loRequestStream.Write(laBytes, 0, laBytes.Length);
loRequestStream.Close();
loRequest.ContentType = "text/xml";
loRequest.Headers.Add("Translate", "F");
loResponse = (HttpWebResponse)loRequest.GetResponse();
loResponseStream = loResponse.GetResponseStream();
loXmlDoc.Load(loResponseStream);
loResponseStream.Close();
i remove the domain name from the user name and it is now working...
There are various things that could be going wrong here:
You can't establish a connection to the actual server.
You can't establish a connection to the mail server.
I'd check that the network credentials you have are valid and give you the access you need.
Something else that's just sprung to mind is to check that you're trying to connect on the correct port. Connecting interactively will do this as the programs you use will have the ports set up, however in your program you'll need to set the port. The server could be set up to reject connections on the "wrong" ports.

Categories