从VB.NET读取SQL脚本 [英] Reading a SQL script from VB.NET

查看:63
本文介绍了从VB.NET读取SQL脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

向大家致以问候,请为以下问题提供帮助:



使用Vb.net 2012,我创建了一个带有意图的sql脚本从我的vb.net应用程序中读取和执行它。我将文件存储在应用程序startuppath中,并使用下面的代码引用它,如下所示,但我不断收到错误:

找不到文件'C:\ Users \ User \ Document \ Visual Studio 2012 \Projects\E_Service_Mgr_V2 \ E_Service_Mgr_V2 \\\\Debug \ E_ITM_DB_OBJ'。





文件名是 E_ITM_DB_OBJ。

任何帮助都将不胜感激。



感谢您的期待。

Frank



我尝试了什么:



我试过改变路径和使用完整路径名,但得到相同的结果。

请帮忙。



谢谢。

使用sr As StreamReader = New StreamReader(Application.StartupPath&\ E_ITM_DB_OBJ )
st = sr.ReadToEnd()
Dim server As New Server(New ServerConnection(con))
server.ConnectionContext.ExecuteNonQuery(st)
End using

解决方案

将该路径复制到剪贴板,没有最后一部分 - 直到最后一个'\'字符:

 C:\ Users \ User.Documents \ Visual Studio 2012 \Projects\E_Service_Mgr_V2 \E_Service_Mgr_V2 \bin\Debug 

现在按住Windows按键并按E键 - 这将打开Windows资源管理器。

单击地址栏,显示此PC并粘贴路径。按ENTER键

如果它给你一个错误,你的EXE文件的路径是错误的,你需要看看你从哪里得到它。

如果没有,它将打开文件夹 - 开始寻找名为E_ITM_DB_OBJ的文件。

如果您发现任何文件,请仔细查看并检查任何扩展名 - 没有文件的文件是不寻常的,因为它是Windows用来确定做什么的扩展名用一个文件。最可能的是它存在,但该ID具有扩展名,如。SQL,。DB,甚至.TXT。如果确实如此,那么当您尝试打开它时,您需要在文件名中使用该扩展名,否则Windows将无法找到它。


非常感谢所有对我的问题发表评论的人。我可以使用以下程序检查它:



1.显示解决方案资源管理器中的所有文件

2.找到bin> ; deburg文件夹并右键单击它

3.Selected从上下文菜单中添加现有项目

4.添加文件,就是这样。



感谢大家。然而,在此之后我遇到了另一个问题。正在读取文件时出现以下错误:

混合模式程序集是针对运行时版本'v2.0.50727'构建的,无法在4.0中加载没有其他配置信息的运行时。





我已经尝试在以下目录中找到SGEn.EXE.CONFIG:

 C:\Program Files(x86)\ Microsoft SDKs \ Windows \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > 

                < supportedRuntime version =v4.0/>

    < /启动>&NBSP;&NBSP;&NBSP;

到配置部分,但我被拒绝保存或覆盖文件。





我还是非常需要帮助。



感谢您的期待。


向大家致以问候,谢谢大家的帮助。我已经能够通过将以下设置添加到应用程序配置文件的启动标记来解决此问题:

< startup useLegacyV2RuntimeActivationPolicy =true> 





再次感谢您的帮助。


Greetings to you all, please i am in need of help with the following issue:

Using Vb.net 2012, I created a sql script with the intention to read and execute it from my vb.net application. i stored the file in the application startuppath and referenced it with the following code as stated bellow but i kept getting the error:

Could not find file 'C:\Users\User\Documents\Visual Studio 2012\Projects\E_Service_Mgr_V2\E_Service_Mgr_V2\bin\Debug\E_ITM_DB_OBJ'.



The file name is "E_ITM_DB_OBJ".
Any help with this will be appreciated.

Thanks in anticipation.
Frank

What I have tried:

I've tried changing the path and using the full path name, but got the same result.
Please help.

Thanks.

Using sr As StreamReader = New StreamReader(Application.StartupPath & "\E_ITM_DB_OBJ")
            st = sr.ReadToEnd()
            Dim server As New Server(New ServerConnection(con))
            server.ConnectionContext.ExecuteNonQuery(st)
        End Using

解决方案

Copy that path to the clipboard, without the final part - up to the last '\' character:

C:\Users\User\Documents\Visual Studio 2012\Projects\E_Service_Mgr_V2\E_Service_Mgr_V2\bin\Debug

Now hold the Windows Key and press E - this will open Windows explorer.
Click on the address bar where it says "This PC" and paste the path. Press ENTER
If it gives you an error, the path to your EXE file is wrong, and you need to look at where you got it from.
If not, it will open the folder - start looking for files called E_ITM_DB_OBJ.
If you find any, look closely and check for any extension - a file without one is unusual as it's the extension Windows uses to determine what to do with a file. The most likely thing is that it's there, but that id has an extension such as ".SQL", ".DB", or even ".TXT". If it does, then you need that extension in your filename when you try to open it or Windows will not find it.


Thanks so much to you all who commented on my question. I was able to go over it using the following procedures:

1.Show all files from the solution explorer
2.Located the bin>deburg folder and right clicked on it
3.Selected add existing item from the context menu
4. Added the file and that was it.

Thanks to you all. How ever, i encountered another issue after this. I was getting the following error while the file is being read:
"

Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.

"

I have tried locating the SGEn.EXE.CONFIG in the following directory:

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin

and added the following:

<startup useLegacyV2RuntimeActivationPolicy="true">

                <supportedRuntime version="v4.0" />

    </startup>    

to the config section but i was denied access to save or overwrite the file.


I am Still in dear need of help with this.

Thanks in anticipation.


Greetings to you all and thank you all for your assistance. I have been able to overcome the issue by adding the following settings to the startup tag of the application's config file:

<startup useLegacyV2RuntimeActivationPolicy="true">



Again thanks for the help.


这篇关于从VB.NET读取SQL脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆