计算机目录读取,从项目目录中读取SQL查询文件(Read SQL query file from project directory)...

从项目目录中读取SQL查询文件(Read SQL query file from project directory)

我在Visual Studio项目中放置了3个特别大的SQL查询,位于项目目录中的“查询”文件夹下(不是解决方案)。 有没有一种雄辩的方式来访问这些文件? 我希望像@"Queries/firstSqlQuery.sql这样的东西可行。

指定完整路径,比如@"C:\\Users\John\Documents\VisualStudio2010\Projects\MySolution\MyProject\Queries\firstSqlQuery.sql是我真的不想做的事情,因为它需要我回到代码并修复路径,如果应用程序移动。

编辑:由于某种原因,该页面正在C:\\Program Files(x86)\Common Files\Microsoft Shared\DevServer\Queries\firstSqlQuery.sql 。 当可执行文件目录不同时,为什么要查看此位置?

I've put 3 especially large SQL queries within my Visual Studio project, under a folder "Queries" that is in the project directory (not the solution). Is there an eloquent way to access these files? I was hoping that something like @"Queries/firstSqlQuery.sql would work.

Specifying the full path, like with @"C:\\Users\John\Documents\VisualStudio2010\Projects\MySolution\MyProject\Queries\firstSqlQuery.sql is something I'd really rather not do, since it requires me to go back into code and fix the path, should the application move.

EDIT: For some reason, the page is looking for the files in C:\\Program Files(x86)\Common Files\Microsoft Shared\DevServer\Queries\firstSqlQuery.sql. Why is it looking in this location, when the executable directory is different?

原文:https://stackoverflow.com/questions/16984269

2019-11-29 16:11

满意答案

你可以做这样的事情......如果它在项目之外。 (当我初读这篇文章时 - 我误读并认为它在我假设包含该项目的解决方案目录中) -

var pathToBin = Assembly.GetExecutingAssembly().Location;

var directoryInfoOfBin = new DirectoryInfo(pathToBin);

var solutionDirectory = directory.Parent().Parent();

var pathToSolution = solutionDirectory.FullName;

但如果它在项目中,这会简单得多

System.Web.HttpContext.Current.Server.MapPath("~/Queries/firstSqlQuery");

You can do something like this... if it's outside of project. (When I intitially read this-- I misread and thought it was in the solution directory which I was assuming contained the project)--

var pathToBin = Assembly.GetExecutingAssembly().Location;

var directoryInfoOfBin = new DirectoryInfo(pathToBin);

var solutionDirectory = directory.Parent().Parent();

var pathToSolution = solutionDirectory.FullName;

but this is much simpler if it's in the project

System.Web.HttpContext.Current.Server.MapPath("~/Queries/firstSqlQuery");

相关问答

从解决方案资源管理器中,右键单击myfile.txt并选择“属性” 从那里,将Build Action设置为content并Copy to Output Directory以使其Copy always Copy if newer或Copy if newer From Solution Explorer, right click on myfile.txt and choose "Properties" From there, set the Build Action to content and ...

请参阅: 支持的.NET Framework库 仍然可以从托管存储过程,触发器,用户定义函数,用户定义类型和用户定义聚合中调用不受支持的库。 必须首先使用CREATE ASSEMBLY语句在SQL Server数据库中注册不受支持的库,然后才能在代码中使用它。 应检查并测试在服务器上注册和运行的任何不受支持的库的安全性和可靠性。 例如,不支持System.DirectoryServices命名空间。 您必须先注册具有UNSAFE权限的System.DirectoryServices.dll程序集,...

你问题中的图像不是一个项目。 它是SSMS对象资源管理器,是您连接到的数据库服务器上对象的分层视图。 SSMS项目的默认位置是C:\Users\\Documents\SQL Server Management Studio 。 The image in your question is not a project. It is SSMS Object Explorer, a hierarchical view of objects on the database server...

尝试使用动态SQL,因为您在OPENROWSET中使用参数 DECLARE @i int = 1

DECLARE @file AS nvarchar(MAX)

DECLARE @sql VARCHAR(max)

WHILE(@i<=50)

BEGIN

SET @file = 'C:\Users\Barry\Desktop\Output\output' + cast(@i as varchar(2)) + '.txt';

SET @sql = '

INSERT INTO dbo.[...

CLR存储过程最适合这样的任务。 MSDN : 创建CLR存储过程 。 如何 创建和运行CLR SQL Server存储过程 也看到这个SO答案 ,有一些你需要的代码。 这个创建一个CLR函数(代码粘贴在下面)。 public partial class UserDefinedFunctions

{

[SqlFunction(DataAccess = DataAccessKind.Read,

FillRowMethodName = "GetFiles_FillRow", T...

编写一个CLR storedprocedure(c#),它读取图像文件的内容并将其作为varbinary(MAX)返回。 Write a CLR storedprocedure (c#) which reads the contents of the image file and returns it as a varbinary(MAX).

你可以做这样的事情......如果它在项目之外。 (当我初读这篇文章时 - 我误读并认为它在我假设包含该项目的解决方案目录中) - var pathToBin = Assembly.GetExecutingAssembly().Location;

var directoryInfoOfBin = new DirectoryInfo(pathToBin);

var solutionDirectory = directory.Parent().Parent();

var pathToSolution ...

您可能想要尝试的是使用: AssetManager am = getAssets();

InputStream is;

is = am.open(pathToFile.txt);

然后使用byte []缓冲区(使用is.available();获取大小)和is.read(缓冲区)读取后不要忘记is.close()。 如果您不在Activity中,则必须使用context.getAssets()才能获取AssetManager。 希望对你有所帮助。 What you might want to t...

我们首先开始调试文件路径问题。 你可以在这里使用两件事。 function db_data() {

WP_Filesystem();

global $wp_filesystem;

global $wpdb;

echo 'Current Path is '. __DIR__;

$file = __DIR__."/sql/my_insert_query.sql";

if(!is_readable($file)) {

echo 'File...

如果你使用this.class().getClassLoader().getResourceAsStream("/res/xxx") ,它将尝试从类路径加载资源。 如果您不希望这样做,则需要指定绝对路径。 Classpath上的资源 如果您不希望将资源内置到JAR中,我建议在src/main/resources目录下使用不同的maven项目。 这将创建一个包含文件的jar文件,大小约为500MB。 在此之后,您可以在包含应用程序代码的项目中包含此项目的依赖项。 然后,这将能够使用getResour...

相关文章

出现bad interpreter:No such file or directory的原因 是文件格

...

Hi Pythonistas! 测试和调试 Testing & Debuggi

...

这个是因为本地没有安装php-solr的扩展导致的,安装方法(使用的是ubuntu) cd /opt

...

查询一个对象(实体类必须有一个不带参数的构造方法),使用select查询,基于投影的查询,通过在列表中

...

用source c:\xxx.sql,出现Ignoring query to other databa

...

Java 流(Stream)、文件(File)和IO Java.io包几乎包含了所有操作输入、输

...

有表格如下: t_table 8 想得到这样的结果:(只取有重复的第一个,相同的排除,例如f) 1 a

...

数据库表A 有个字段a是int类型 a中有数据有1到9任意(有重复的) 想取得a中,当 a=1时

...

Solr1.4 Both delete by id and delete by query can b

...

查询操作符(Query Operators)可以让我们写出复杂查询条件,让我们使用的过程更加灵活。官方

...

最新问答

找到了完全相同的东西: http : //www.dragonbyte-tech.com/product/40-vbcredits-ii-deluxe/ Found something that does exact same thing: http://www.dragonbyte-tech.com/product/40-vbcredits-ii-deluxe/

不知道任何可以实际切换的调试器,但您可以将两个调试器连接到您的进程。 在调试模式下在Java IDE中启动Java程序会附加Java调试器。 然后打开用于CPP代码的IDE,并将其调试器附加到正在运行的Java进程。 在Visual Studio中,这将是Debug -> Attach to Process... 您将看到一个包含进程列表的对话框。 在这里选择您的Java进程。 如果Visual Studio无法正确检测到,您可能必须将列表上方的字段切换为“本机代码”。 在CPP代码中设置适当的

您需要使用ajax发送该变量。 $.get('your.jsp', {data: $('#'+this.id+'t').val()}, function(response) { console.log(response); }); You need to send that variable using ajax. $.get('your.jsp', {data: $('#'+this.id+'t').val()}, function(response) { console.l

确保已设置root密码(sudo su passwd)根据ssh的安装方式,通常需要编辑/ etc / ssh / sshd_config并将“PermitRootLogin no”更改为“PermitRootLogin yes” Make sure you have set a root password (sudo su passwd) Depending how your ssh is installed, you usually need to edit /etc/ssh/sshd_co

看看FMDB的用法 。 [db executeUpdate:@"INSERT INTO notes VALUES (?,?,?)", title, comment, [NSNumber numberWithInt:fkID]]; 提供给-executeUpdate:方法的所有参数(或接受va_list作为参数的任何变体)都必须是对象。 Here is what I ended up doing. NSString *sql = [NSString stringWithFormat:

我后来发现这是一个与多德兴相关的问题。 我需要运行一个脚本来为我的main-dex-list生成文件的名称 下面的博客文章详细介绍了这一点: http : //blog.osom.info/2014/10/generating-main-dex-list-file.html I later found out that this was an issue relating to multi dexing. I needed to run a script to generate the name

使用OAuth 2.0,您可以使用可扩展的标准和基于令牌的身份验证,使用户可以撤消身份验证票证,例如,如果他们的手机被盗。 OAuth 2.0支持各种授权类型。 那些来自facebook和twitter登录的人可以概括为“3-legged oauth”,但是对于2-legged OAuth,还有两种授权类型,特别是资源所有者密码凭证授权 (页面末尾的第4.3节),这将是只需交换身份验证令牌的用户名和密码即可。 如果你不愿意,就没有必要实施三条腿的oauth。 对于大多数用例,我建议在基于加密的自

您应该将此作为多个连接进行处理。 特别是,您需要为电子邮件的“从”和“到”部分单独加入: SELECT e.EmailID as id, e.DateStamp as timed, edfrom.profileid as sender, edto.profileid as receiver FROM EmailDirection edfrom join Email e on edfrom.emailid = e.emailid and ed.direction

问题根本不是ngZone 。 事实上,您正在使用更改this值的常规函数。 所以this.distance内的this.distance距离function(response,status)是不同的。 尝试: (response, status)=> { if (status === 'OK') { directionsDisplay.setDirections(response); var total = 0; var rou

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值