-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrawlerDB.cs
62 lines (57 loc) · 2.84 KB
/
CrawlerDB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Data.SqlClient;
using System.Data;
using System.Globalization;
using System.Configuration;
namespace FileCrawler
{
public class CrawlerDB
{
public String DB_CONN_STRING = null;
public CrawlerDB(String connection)
{
DB_CONN_STRING = connection;
}
#region "Inserts new url to database | SaveFileURLToDB"
/// <summary>
/// Method to Insert a new URL to the specified table to Database
/// </summary>
/// <param name="tableName">The Table name to which the URL will be Inserted</param>
/// <param name="hostName">The url host</param>
/// <param name="fileType">the type of file to be Inserted</param>
/// <param name="fileDescription">File Description</param>
/// <param name="fileUrl">The URL of the file</param>
public void SaveFileURLToDB(String tableName, String hostName, string fileType, string fileDescription,string fileUrl)
{
using (SqlConnection con = new SqlConnection(DB_CONN_STRING))
{
con.Open();
try
{
using (SqlCommand command = new SqlCommand("INSERT INTO [FileCrawler].[dbo].[" + tableName + "] VALUES(@hostName,@fileType,@fileDescription,@url,@createdDt,@createdByName,@updatedDt,@updatedByName)", con))
{
command.Parameters.Add(new SqlParameter("hostName", hostName));
command.Parameters.Add(new SqlParameter("fileType", fileType));
command.Parameters.Add(new SqlParameter("fileDescription", fileDescription));
command.Parameters.Add(new SqlParameter("url", fileUrl));
command.Parameters.Add(new SqlParameter("createdDt", DateTime.Now.ToString()));
command.Parameters.Add(new SqlParameter("createdByName",Environment.MachineName + "/" + Environment.UserName));
command.Parameters.Add(new SqlParameter("updatedDt", DBNull.Value));
command.Parameters.Add(new SqlParameter("updatedByName", DBNull.Value));
command.ExecuteNonQuery();
}
}
catch (Exception ex)
{
System.Console.WriteLine("**************************************");
System.Console.WriteLine("WRITING: ERROR DESCRIPTION");
System.Console.WriteLine(" Error Message:" + ex.Message);
System.Console.WriteLine(" Stack Trace :" + ex.StackTrace);
System.Console.WriteLine(" Connection String.:" + DB_CONN_STRING);
System.Console.WriteLine("**************************************");
}
}
}
#endregion
}
}