473,657 Members | 2,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add item to resource? Or library?

Hello group.

Here is what I like to do.

#1. Add ".SQL" file to project
#2. Being able to load contents of this file into string variable.

So, I want .SQL to be compiled into executable and being able to retreive
contents for use inside program.

To explain what I'm doing:
I have app that interacts with DB. Some objects that needed is Stored
procedures and temp tables. My idea is instead of supplying separate DB
install - I rather have client refresh those objects on every startup. It's
utility and this approach will work just fine.

I can probably add this SQL like a string constants but it's PITA to manage.
Would be much prettier if I had it in SQL files so I can edit them in SQL
Management Studio

Thank you,
Ivan

Nov 6 '08 #1
7 2492
Ivan,

If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make use
of the Resources section of your Project Properties. Go there and choose the
expando button next to "Add Resource". This will allow you to add an
existing file (the .SQL one). Visual Studio will recognize that it as a text
file and you can get the string contents like this:

string sqlContents = Properties.Reso urces.{Resource/FileName};
--
Stanimir Stoyanov
http://stoyanoff.info

"Ivan" <iv**@mailgroup s.microsoft.com wrote in message
news:77******** *************** ***********@mic rosoft.com...
Hello group.

Here is what I like to do.

#1. Add ".SQL" file to project
#2. Being able to load contents of this file into string variable.

So, I want .SQL to be compiled into executable and being able to retreive
contents for use inside program.

To explain what I'm doing:
I have app that interacts with DB. Some objects that needed is Stored
procedures and temp tables. My idea is instead of supplying separate DB
install - I rather have client refresh those objects on every startup.
It's utility and this approach will work just fine.

I can probably add this SQL like a string constants but it's PITA to
manage. Would be much prettier if I had it in SQL files so I can edit them
in SQL Management Studio

Thank you,
Ivan
Nov 6 '08 #2
"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:01******** *************** ***********@mic rosoft.com...
If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
use of the Resources section of your Project Properties. Go there and
choose the expando button next to "Add Resource". This will allow you to
add an existing file (the .SQL one). Visual Studio will recognize that it
as a text file and you can get the string contents like this:

string sqlContents = Properties.Reso urces.{Resource/FileName};
Most of the things I add via Add Existing File get classified as byte
arrays, not strings (even when they're text files, like XML). Or does the
IDE convert it for you?
Nov 6 '08 #3
I suppose the IDE does a quick check of the content to determine the best
matching data type. Not 'catching' the text or XML files might be related to
the encoding those files use.
--
Stanimir Stoyanov
http://stoyanoff.info

"Jeff Johnson" <i.***@enough.s pamwrote in message
news:ub******** ******@TK2MSFTN GP02.phx.gbl...
"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:01******** *************** ***********@mic rosoft.com...
>If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
use of the Resources section of your Project Properties. Go there and
choose the expando button next to "Add Resource". This will allow you to
add an existing file (the .SQL one). Visual Studio will recognize that it
as a text file and you can get the string contents like this:

string sqlContents = Properties.Reso urces.{Resource/FileName};

Most of the things I add via Add Existing File get classified as byte
arrays, not strings (even when they're text files, like XML). Or does the
IDE convert it for you?
Nov 6 '08 #4
I found another way.

I add file, mark it to "Embed"

Then write code:

StreamReader streamReader = new
StreamReader(As sembly.GetExecu tingAssembly(). GetManifestReso urceStream("Myn amespace.Folder .FileName.Exten tion"));
string sSQL = streamReader.Re adToEnd();

SqlCommand sc = new SqlCommand(sSQL , DynamicsGPConne ction);
sc.ExecuteNonQu ery();

"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:B7******** *************** ***********@mic rosoft.com...
>I suppose the IDE does a quick check of the content to determine the best
matching data type. Not 'catching' the text or XML files might be related
to the encoding those files use.
--
Stanimir Stoyanov
http://stoyanoff.info

"Jeff Johnson" <i.***@enough.s pamwrote in message
news:ub******** ******@TK2MSFTN GP02.phx.gbl...
>"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:01******* *************** ************@mi crosoft.com...
>>If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
use of the Resources section of your Project Properties. Go there and
choose the expando button next to "Add Resource". This will allow you to
add an existing file (the .SQL one). Visual Studio will recognize that
it as a text file and you can get the string contents like this:

string sqlContents = Properties.Reso urces.{Resource/FileName};

Most of the things I add via Add Existing File get classified as byte
arrays, not strings (even when they're text files, like XML). Or does the
IDE convert it for you?
Nov 6 '08 #5
"Ivan" <iv**@mailgroup s.microsoft.com wrote in message
news:99******** *************** ***********@mic rosoft.com...
>I found another way.
I consider that a "longer" way as well.
Nov 6 '08 #6
That's exactly what I was avoiding with the Resources method. But I presume
you use .NET 1.1 (that's how I would do it there).

The reasons I avoid this is because you have to hardcode the fully-qualified
resource name, use kind of dirty Reflection code and StreamReaders for
something VS can present to you in a straight-forward object-oriented way.
--
Stanimir Stoyanov
http://stoyanoff.info

"Ivan" <iv**@mailgroup s.microsoft.com wrote in message
news:99******** *************** ***********@mic rosoft.com...
>I found another way.

I add file, mark it to "Embed"

Then write code:

StreamReader streamReader = new
StreamReader(As sembly.GetExecu tingAssembly(). GetManifestReso urceStream("Myn amespace.Folder .FileName.Exten tion"));
string sSQL = streamReader.Re adToEnd();

SqlCommand sc = new SqlCommand(sSQL , DynamicsGPConne ction);
sc.ExecuteNonQu ery();

"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:B7******** *************** ***********@mic rosoft.com...
>>I suppose the IDE does a quick check of the content to determine the best
matching data type. Not 'catching' the text or XML files might be related
to the encoding those files use.
--
Stanimir Stoyanov
http://stoyanoff.info

"Jeff Johnson" <i.***@enough.s pamwrote in message
news:ub******* *******@TK2MSFT NGP02.phx.gbl.. .
>>"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:01****** *************** *************@m icrosoft.com...

If you use Visual Studio 2005 (that is, .NET 2.0) or later you can make
use of the Resources section of your Project Properties. Go there and
choose the expando button next to "Add Resource". This will allow you
to add an existing file (the .SQL one). Visual Studio will recognize
that it as a text file and you can get the string contents like this:

string sqlContents = Properties.Reso urces.{Resource/FileName};

Most of the things I add via Add Existing File get classified as byte
arrays, not strings (even when they're text files, like XML). Or does
the IDE convert it for you?
Nov 7 '08 #7
I see your point, I changed it to do like you suggested, intellisence, etc.
Nice.

Now I realized that if I want to have unlimited number of scripts I can just
name them "1.sql", "2.sql" and so on and add to resources. Then method I
specified can be used to pull files using reflection and then it would just
error out when all files done.

"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:AB******** *************** ***********@mic rosoft.com...
That's exactly what I was avoiding with the Resources method. But I
presume you use .NET 1.1 (that's how I would do it there).

The reasons I avoid this is because you have to hardcode the
fully-qualified resource name, use kind of dirty Reflection code and
StreamReaders for something VS can present to you in a straight-forward
object-oriented way.
--
Stanimir Stoyanov
http://stoyanoff.info

"Ivan" <iv**@mailgroup s.microsoft.com wrote in message
news:99******** *************** ***********@mic rosoft.com...
>>I found another way.

I add file, mark it to "Embed"

Then write code:

StreamReader streamReader = new
StreamReader(A ssembly.GetExec utingAssembly() .GetManifestRes ourceStream("My namespace.Folde r.FileName.Exte ntion"));
string sSQL = streamReader.Re adToEnd();

SqlCommand sc = new SqlCommand(sSQL , DynamicsGPConne ction);
sc.ExecuteNonQu ery();

"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:B7******* *************** ************@mi crosoft.com...
>>>I suppose the IDE does a quick check of the content to determine the best
matching data type. Not 'catching' the text or XML files might be related
to the encoding those files use.
--
Stanimir Stoyanov
http://stoyanoff.info

"Jeff Johnson" <i.***@enough.s pamwrote in message
news:ub****** ********@TK2MSF TNGP02.phx.gbl. ..
"Stanimir Stoyanov" <st******@REMOV ETHIS.live.comw rote in message
news:01***** *************** **************@ microsoft.com.. .

If you use Visual Studio 2005 (that is, .NET 2.0) or later you can
make use of the Resources section of your Project Properties. Go there
and choose the expando button next to "Add Resource". This will allow
you to add an existing file (the .SQL one). Visual Studio will
recognize that it as a text file and you can get the string contents
like this:
>
string sqlContents = Properties.Reso urces.{Resource/FileName};

Most of the things I add via Add Existing File get classified as byte
arrays, not strings (even when they're text files, like XML). Or does
the IDE convert it for you?

Nov 7 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
13133
by: Danny Pressley | last post by:
I have a VS.NET 2003 Visual C++ MFC Application Project in which I added a new resource file, I then added an icon to this new resource file and did a rebuild and got the following error: "fatal error CVT1100: duplicate resource. type:ICON, name:1, language:0x0409". But the resource ID is unique and only located in the new Resource1.h and MyResourceFile.rc files. Any ideas why this error is occuring? To generate the issue real quick, you...
7
5406
by: Wysiwyg | last post by:
Is there any way to add an embedded resource to a project without copying it to the project's directory? I have shared resources and don't want each project using the images, xml files, etc. to need to be updated with the current copy before being built. I also don't want projects being built with the old copy. Thanks! Bill
0
2962
by: Mythran | last post by:
I wrote some code that is supposed to enumerate through the specified file's win32 resources and return a string-array of all icon names. When it runs, it returns a string-array with a bunch of numbers in sequential order (1-55 when ran against iexplore.exe). When I open up iexplore.exe in Visual Studio, I see 23 icons. Each icon has 1 or more sizes of the icon...I'm assuming that there are, in fact, 55 icon resources in iexplore.exe,...
8
6072
by: Andreas Zita | last post by:
Hi Im creating my first 2.0 site and I cant find the Build Action property? I want to embedd an image-file in my site-assembly but I don't know how? In 1.1 I could set Build Action to Embedded Resource in the properties pane but this doesn't seem to be available any more??? /Andreas
2
6212
by: Al | last post by:
Hi, I have created a solution with two projects in it - a class library and a windows forms front end. I have added a resource file (Resources.resx) to the class library and filled it with icons. Does anybody know how would I go about using an icon from this resource file in the windows forms project? Thanks in advance, Al.
1
1896
by: vecozo | last post by:
Centralized resource files Hi, We are considering to migrate our custom asp.net localization procedure, to one that stored .Text properties of controls in a SQL database, towards the usage of standard resources (hence .resx files). Plain Resx files do not seem to be a very scalable solution: We have dozens of servers and we do not want to access all servers to deploy files in case of minor changes in the personalized text. So we need...
8
13658
by: CodeLeon | last post by:
Hi, All. I am creating a setup program. The way it works is that the user creates their setup info, my program generates the C# code for a setup executable, embeds the xml file containing the info for the setup, and compiles the whole thing into one EXE. How do i embed resources, and access them, into that assembly?
2
10733
by: WT | last post by:
Hello, Could we use 'Embedded resources' with resx files that contain text resources used in aspx pages with the syntaxe: Text="<%$ Resources:ResourcesMy,KEY1 %>" I tryed removing the App_GlobalResources folder, and after verifying thta my resources were correctly embedded in my dll, I get errors as if asp.net was
2
2650
by: Justin | last post by:
Hi Guys, I am writing a static library in which there are some resrouces - BMPs and dialogs etc. Unfortunately, when I call functions/dialogs in the static library, it failed because of resource could not be located. I have googled. But the approach I found is to include resources of the static library in the caller. Are there some other more graceful way to do this? I mean just like resource in DLL file, do not include resources in...
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7327
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4152
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.