473,395 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 2486
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.Resources.{Resource/FileName};
--
Stanimir Stoyanov
http://stoyanoff.info

"Ivan" <iv**@mailgroups.microsoft.comwrote in message
news:77**********************************@microsof t.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******@REMOVETHIS.live.comwrote in message
news:01**********************************@microsof t.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.Resources.{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.spamwrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
"Stanimir Stoyanov" <st******@REMOVETHIS.live.comwrote in message
news:01**********************************@microsof t.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.Resources.{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(Assembly.GetExecutingAssembly().GetMa nifestResourceStream("Mynamespace.Folder.FileName. Extention"));
string sSQL = streamReader.ReadToEnd();

SqlCommand sc = new SqlCommand(sSQL, DynamicsGPConnection);
sc.ExecuteNonQuery();

"Stanimir Stoyanov" <st******@REMOVETHIS.live.comwrote in message
news:B7**********************************@microsof t.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.spamwrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
>"Stanimir Stoyanov" <st******@REMOVETHIS.live.comwrote in message
news:01**********************************@microso ft.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.Resources.{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**@mailgroups.microsoft.comwrote in message
news:99**********************************@microsof t.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**@mailgroups.microsoft.comwrote in message
news:99**********************************@microsof t.com...
>I found another way.

I add file, mark it to "Embed"

Then write code:

StreamReader streamReader = new
StreamReader(Assembly.GetExecutingAssembly().GetMa nifestResourceStream("Mynamespace.Folder.FileName. Extention"));
string sSQL = streamReader.ReadToEnd();

SqlCommand sc = new SqlCommand(sSQL, DynamicsGPConnection);
sc.ExecuteNonQuery();

"Stanimir Stoyanov" <st******@REMOVETHIS.live.comwrote in message
news:B7**********************************@microsof t.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.spamwrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
>>"Stanimir Stoyanov" <st******@REMOVETHIS.live.comwrote in message
news:01**********************************@micros oft.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.Resources.{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******@REMOVETHIS.live.comwrote in message
news:AB**********************************@microsof t.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**@mailgroups.microsoft.comwrote in message
news:99**********************************@microsof t.com...
>>I found another way.

I add file, mark it to "Embed"

Then write code:

StreamReader streamReader = new
StreamReader(Assembly.GetExecutingAssembly().GetM anifestResourceStream("Mynamespace.Folder.FileName .Extention"));
string sSQL = streamReader.ReadToEnd();

SqlCommand sc = new SqlCommand(sSQL, DynamicsGPConnection);
sc.ExecuteNonQuery();

"Stanimir Stoyanov" <st******@REMOVETHIS.live.comwrote in message
news:B7**********************************@microso ft.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.spamwrote in message
news:ub**************@TK2MSFTNGP02.phx.gbl...
"Stanimir Stoyanov" <st******@REMOVETHIS.live.comwrote in message
news:01**********************************@micro soft.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.Resources.{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
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...
7
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...
0
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...
8
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...
2
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....
1
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...
8
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...
2
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.