{"id":6459,"date":"2017-09-27T11:57:15","date_gmt":"2017-09-27T16:57:15","guid":{"rendered":"http:\/\/appcrawler.com\/wordpress\/?p=6459"},"modified":"2017-09-27T11:58:49","modified_gmt":"2017-09-27T16:58:49","slug":"c-write-file-on-client-and-read-same-file-from-inside-the-database","status":"publish","type":"post","link":"http:\/\/appcrawler.com\/wordpress\/2017\/09\/27\/c-write-file-on-client-and-read-same-file-from-inside-the-database\/","title":{"rendered":"C# &#8211; Write file on client and read same file from inside the database"},"content":{"rendered":"<p>We had a job that an enterprise software vendor was running that failed on permissions denied.  They asked us to open the file share to anyone without a password.  Our awesome SQL Server DBA pushed back, thankfully.  We came up with what is below to troubleshoot.<\/p>\n<p>This allowed us to reproduce the condition, the root cause of which was traced back to a subdomain issue.  Quick POC&#8217;s like this enable you to troubleshoot much more quickly, even with monolithic enterprise apps.  This is only true if you can mimic the &#8220;big picture&#8221; behavior of the app.  In this case, it was read a file, write the file, and then insert it in the database from the same location you wrote the file on the client.<\/p>\n<pre>\r\nusing System.IO;\r\nusing System;\r\nusing System.Data.SqlClient;\r\n\r\n\/\/C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc.exe \r\n\r\nclass WriteTextFile {\r\n  static void Main() {\r\n    string[] lines = { \"One\", \"Two\", \"Three\" };\r\n    System.IO.File.WriteAllLines(@\"\\\\cmhfiler2\\amspromo\\sdh_poc.txt\", lines);\r\n    SqlConnection conn = new SqlConnection(\"Data Source=dbserver;Initial Catalog=dbname;Integrated Security=True;\");\r\n    conn.Open();\r\n    SqlCommand command = new SqlCommand(\"select * from openrowset(bulk '\\\\\\\\cmhfiler2\\\\amspromo\\\\sdh_poc.txt', single_clob)\", conn);\r\n    SqlDataReader rdr = command.ExecuteReader();  \r\n    while (rdr.Read())  {              \r\n      Console.WriteLine(\"Line is \" + rdr[0]);\r\n    }  \r\n  }\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We had a job that an enterprise software vendor was running that failed on permissions denied. They asked us to open the file share to anyone without a password. Our awesome SQL Server DBA pushed back, thankfully. We came up&hellip;<\/p>\n<p class=\"more-link-p\"><a class=\"more-link\" href=\"http:\/\/appcrawler.com\/wordpress\/2017\/09\/27\/c-write-file-on-client-and-read-same-file-from-inside-the-database\/\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[39,34],"tags":[],"_links":{"self":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6459"}],"collection":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/comments?post=6459"}],"version-history":[{"count":4,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6459\/revisions"}],"predecessor-version":[{"id":6463,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/posts\/6459\/revisions\/6463"}],"wp:attachment":[{"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/media?parent=6459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/categories?post=6459"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/appcrawler.com\/wordpress\/wp-json\/wp\/v2\/tags?post=6459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}