吻你一生 发表于 2023-9-13 14:26:06

执行存储作为资源SQL脚本

我想在解决方案中存储冗长的.sql脚本以编程的方式执行。我已经想出了如何执行包括我在内的内容。sql脚本字符串,但还没有想出如何从存储在解决方案中的文件中读取字符串(例如/
Scripts夹下子文件)。
                                                               
    解决方案:                                                               
                                                                首先,编辑.sql文件的属性,以便将其作为资源嵌入。
然后用类似以下代码的代码检索脚本:
string commandText;Assembly thisAssembly = Assembly.GetExecutingAssembly();using (Stream s = thisAssembly.GetManifestResourceStream(       "{project default namespace}.{path in project}.{filename}.sql")){   using (StreamReader sr = new StreamReader(s))                                                                                                                                                                                                                              commandText = sr.ReadToEnd();
页: [1]
查看完整版本: 执行存储作为资源SQL脚本