code_junkie

Slow MSAccess disk writing

Nov 12th, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. using System;
  2. using System.Data;
  3. using System.Data.OleDb;
  4.  
  5. namespace ConsoleApplication1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. String jetConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\jetsample.mdb;";
  12.  
  13. ADOX.CatalogClass cat = new ADOX.CatalogClass();
  14. cat.Create(jetConnection);
  15.  
  16. using(OleDbConnection conn = new OleDbConnection(jetConnection))
  17. {
  18. conn.Open();
  19. using(OleDbCommand cmd = new OleDbCommand("CREATE TABLE test ([ID] INTEGER, [TestDouble] DOUBLE, [TestText] TEXT, [TestDate] DATE, [TestInt] INTEGER)",conn))
  20. {
  21. cmd.CommandType = CommandType.Text;
  22. cmd.ExecuteNonQuery();
  23. }
  24.  
  25. using (OleDbCommand cmd = new OleDbCommand("INSERT INTO [Test] VALUES (@id, @testDouble, @testText, @testDate, @testInt)", conn))
  26. {
  27. OleDbParameter id = cmd.Parameters.Add("@id", OleDbType.Integer);
  28. OleDbParameter testDouble = cmd.Parameters.Add("@testDouble", OleDbType.Double);
  29. OleDbParameter testText = cmd.Parameters.Add("@testText", OleDbType.VarWChar);
  30. OleDbParameter testDate = cmd.Parameters.Add("@testDate", OleDbType.Date);
  31. OleDbParameter testInt = cmd.Parameters.Add("@testInt", OleDbType.Integer);
  32.  
  33. DateTime start = DateTime.Now;
  34. for (int index = 1; index <= 2000000; index++)
  35. {
  36. if (index % 1000 == 0)
  37. {
  38. System.Diagnostics.Debug.WriteLine(((TimeSpan)(DateTime.Now - start)).Milliseconds);
  39. start = DateTime.Now;
  40. }
  41.  
  42. id.Value = index;
  43. testDouble.Value = index;
  44. testText.Value = String.Format("{0} DBL", index);
  45. testDate.Value = DateTime.Now.AddMilliseconds(index);
  46. testInt.Value = index;
  47.  
  48. cmd.ExecuteNonQuery();
  49. }
  50. }
  51. }
  52.  
  53. }
  54. }
  55. }
  56.  
  57. Set cn = CreateObject("ADODB.Connection")
  58. strFile="C:ltd.mdb"
  59. strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" _
  60. & strFile & ";"
  61.  
  62. cn.Open strCon
  63.  
  64. strSQL="INSERT INTO tableX ( Name1,Name2 ) " _
  65. & "SELECT Name1,Name2 " _
  66. & "FROM [ltd.txt] IN '' [Text;Database=c:docs;HDR=YES;]"
  67.  
  68. cn.Execute strSQL
Add Comment
Please, Sign In to add comment