Visual Studio Database Project and SQL Azure

后端 未结 3 1018
别那么骄傲
别那么骄傲 2021-02-13 15:52

I\'m really struggling with the best approach for managing a SQL Azure database which is based on a Visual Studio 2010 Database Project. I figured it would be easy enough to use

3条回答
  •  名媛妹妹
    2021-02-13 16:25

    A simple command line tool that replaces invalid SQL Azure statements is all that is needed:

        private const string STARTPLACEHOLDER = "AZURESCRIPTSTARTPLACEHOLDER";
    
        public static void Do(string fileName)
        {
            // Read the original file
            StringBuilder script = new StringBuilder();
            using (StreamReader reader = new StreamReader(fileName))
            {
                script.Append(reader.ReadToEnd());
            }
    
            // Remove everything before the start placeholder
            int startPlaceHolder = script.ToString().IndexOf(STARTPLACEHOLDER, 0);
            if (startPlaceHolder > 0)
            {
                script.Remove(0, startPlaceHolder + STARTPLACEHOLDER.Length);
            }
    
            // Remove WITH clause
            script.Replace("WITH (ALLOW_PAGE_LOCKS = ON, ALLOW_ROW_LOCKS = ON, PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, STATISTICS_NORECOMPUTE = OFF)", string.Empty);
    
            // Create azure compatible output file
            using (StreamWriter writer = new StreamWriter(Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + "_Azure" + Path.GetExtension(fileName))))
            {
                writer.Write(script.ToString());
            }
        }
    

提交回复
热议问题