Question : Load XML file into sqlserver 2008 Database using c# :  26366040

this is a follow up to thread  26366040, please go to this one for the background.

I have a procedure in c#
        public void GetAllFiles(string RootPath, string MasterFileFormat)
        {
                    //get the projects and files
            string[] filePaths = Directory.GetFiles(RootPath, MasterFileFormat,
                                         SearchOption.AllDirectories);

            string dpath;
            string fname;
            string SubFileName;
            string MasterFileName;
            int MasterFileCheck; //0 will be master

            FileStream fileStream;


            //get the full path of each file
            foreach (string fpath in filePaths)
            {
                sqlConn = MAC_SQLServerConnection(DBEnv);
                sqlConn.Open();
                sqlConn.Close();

                dpath = Path.GetDirectoryName(fpath); // directory
                fname = Path.GetFileName(fpath); // filename
                SubFileName = Path.GetFileNameWithoutExtension(fname);
                MasterFileName = Path.GetFileNameWithoutExtension(SubFileName);
                MasterFileCheck = SubFileName.Length - MasterFileName.Length;

                Dictionary<string, string> ProcInputs = new Dictionary<string, string>();



                if (MasterFileCheck == 0)
                {   // this is master file
                    Response.Write("Master File");
                    Response.Write("<BR>");
                    Response.Write(dpath);
                    Response.Write("<BR>");
                    Response.Write(fname);
                    Response.Write("<BR>");

                    try //open file
                    {



                        string xmlData = string.Empty;

                        using (TextReader streamReader = new StreamReader(fpath))
                        {
                            xmlData = streamReader.ReadToEnd();
                        }

                        ProcInputs.Add("@XMLDirectory", "XXX");
                        ProcInputs.Add("@XMLFileName", "ABC");
                        ProcInputs.Add("@XMLFile", xmlData);

                        try
                        {
                            if (sqlConn.State == ConnectionState.Closed)
                            {
                                sqlConn = MAC_SQLServerConnection(DBEnv);
                                sqlConn.Open();
                            }

                            //ExecuteSQLServerProcedure(ProcInputs, "resx.dbo.PopulateXMLFile", DBEnv, sqlConn);
                            string sql = string.Format
                                     ("      update dbo.XML_FILE "
                                       +"   set XML_FILE = '{0}'"
                                     +"   where XML_ID =  (select a.XML_ID"
                                                                +"  from dbo.XML_FILE a"
                                                                +"  where a.XML_FileName = '{1}')",
                                 xmlData, MasterFileName);


                            SqlCommand command = new SqlCommand(sql, sqlConn);
                            command.ExecuteNonQuery();

                       
                        }
                        catch (Exception err) { Response.Write(MACErr.GenericErrorMessage(err)); }


                    }
                    catch (Exception err) { Response.Write(MACErr.GenericErrorMessage(err)); }


                }
                else
                {/*
                    // this is sub file
                    Response.Write("<BR>");
                    Response.Write("Sub File");
                    Response.Write(dpath);
                    Response.Write("<BR>");
                    Response.Write(fname);
                    Response.Write("<BR>");
                */
                }
            }
        }//public void GetAllFiles(string RootPath, string MasterFileFormat)

this allows me to look at all teh files I want but when I try to update the xml I get an error.
I inserted one row in the xml table that has a file name "ABC" and I am trying to update the xml field  but I get the following error

Message: Incorrect syntax near 't'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. Incorrect syntax near the keyword 'SET'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon. Incorrect syntax near the keyword 'with'.


I have traced the issue to at least being with how the xml data is being passed to the update, and I dont know how to get aroung the issue

Answer : Load XML file into sqlserver 2008 Database using c# :  26366040

First thing is first you need to get your current AD running properly which that hotfix hopefully will fix it properly.

Then the steps to migrate are pretty easy with this detailed steps.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/Q_23665224.html

Now if you are migrating your current 32-bit DC make sure you run adprep32 off the R2 DVD.
Random Solutions  
 
programming4us programming4us