473,320 Members | 1,863 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,320 software developers and data experts.

How do I include a file

Everyone keeps telling me that I should protect my database connection
information by defining the connection string in a separate file (presumably
one that is not in the application directory).
However, I can't work out how to do this as C# doesn't seem to have an
equivelant of the C/C++ #include directive.
Can someone give me the clue.
--
Dave
Nov 17 '05 #1
8 2203
Dave <Da**@discussions.microsoft.com> wrote:
Everyone keeps telling me that I should protect my database connection
information by defining the connection string in a separate file (presumably
one that is not in the application directory).
However, I can't work out how to do this as C# doesn't seem to have an
equivelant of the C/C++ #include directive.
Can someone give me the clue.


You wouldn't use include in C/C++ either. The idea would be to read the
information from the file at *runtime*. Defining it in a different
compile-time file hardly protects it at all - the most it can do is
obfuscate it slightly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
I don't know why you'd want to have the connection string file on a separate
application directory, but I have done it on a different file (on the same
directory) .Here is what I have done.

I have a log in page that validates username and password from the SQL
server database (don't worry, all passwords are encrypted), so I created a
separate C# file that has a class to connect to the db. On my login page, I
created an object of the class and wala, you are ready to go.

Chao...

Now, I don't know how secure that is (I am sure some of the pundits here
will be able to answer that question), but that's my approach.
"Dave" wrote:
Everyone keeps telling me that I should protect my database connection
information by defining the connection string in a separate file (presumably
one that is not in the application directory).
However, I can't work out how to do this as C# doesn't seem to have an
equivelant of the C/C++ #include directive.
Can someone give me the clue.
--
Dave

Nov 17 '05 #3
I don't know why you'd want to have the connection string file on a separate
application directory, but I have done it on a different file (on the same
directory) .Here is what I have done.

I have a log in page that validates username and password from the SQL
server database (don't worry, all passwords are encrypted), so I created a
separate C# file that has a class to connect to the db. On my login page, I
created an object of the class and wala, you are ready to go.

Chao...

Now, I don't know how secure that is (I am sure some of the pundits here
will be able to answer that question), but that's my approach.
"Dave" wrote:
Everyone keeps telling me that I should protect my database connection
information by defining the connection string in a separate file (presumably
one that is not in the application directory).
However, I can't work out how to do this as C# doesn't seem to have an
equivelant of the C/C++ #include directive.
Can someone give me the clue.
--
Dave

Nov 17 '05 #4
I realised it was a stupid question shortly after I posted it. In actual fact
I would think that having the connection string embedded in the middle of a
compiled .dll was pretty secure - a good deal more secure than reading it in
plain text from another file (unless the file is encrypted of course).
I suspect that all the talk about securing the connection string is aimed at
scripted HTMl files, rather than compiled code-behind files. Nevertheless
when I create a dataconnection in ASP.NET I always get a warning asking if I
want to include the password in the connection string.
This whole security thing is a bit of a maze. Anyway, thanks for responding.
--
Dave
"Jon Skeet [C# MVP]" wrote:
Dave <Da**@discussions.microsoft.com> wrote:
Everyone keeps telling me that I should protect my database connection
information by defining the connection string in a separate file (presumably
one that is not in the application directory).
However, I can't work out how to do this as C# doesn't seem to have an
equivelant of the C/C++ #include directive.
Can someone give me the clue.


You wouldn't use include in C/C++ either. The idea would be to read the
information from the file at *runtime*. Defining it in a different
compile-time file hardly protects it at all - the most it can do is
obfuscate it slightly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #5
I realised it was a stupid question shortly after I posted it. In actual fact
I would think that having the connection string embedded in the middle of a
compiled .dll was pretty secure - a good deal more secure than reading it in
plain text from another file (unless the file is encrypted of course).
I suspect that all the talk about securing the connection string is aimed at
scripted HTMl files, rather than compiled code-behind files. Nevertheless
when I create a dataconnection in ASP.NET I always get a warning asking if I
want to include the password in the connection string.
This whole security thing is a bit of a maze. Anyway, thanks for responding.
--
Dave
"Jon Skeet [C# MVP]" wrote:
Dave <Da**@discussions.microsoft.com> wrote:
Everyone keeps telling me that I should protect my database connection
information by defining the connection string in a separate file (presumably
one that is not in the application directory).
However, I can't work out how to do this as C# doesn't seem to have an
equivelant of the C/C++ #include directive.
Can someone give me the clue.


You wouldn't use include in C/C++ either. The idea would be to read the
information from the file at *runtime*. Defining it in a different
compile-time file hardly protects it at all - the most it can do is
obfuscate it slightly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #6
Dave <Da**@discussions.microsoft.com> wrote:
I realised it was a stupid question shortly after I posted it. In actual fact
I would think that having the connection string embedded in the middle of a
compiled .dll was pretty secure - a good deal more secure than reading it in
plain text from another file (unless the file is encrypted of course).
I suspect that all the talk about securing the connection string is aimed at
scripted HTMl files, rather than compiled code-behind files. Nevertheless
when I create a dataconnection in ASP.NET I always get a warning asking if I
want to include the password in the connection string.
This whole security thing is a bit of a maze. Anyway, thanks for responding.


Just to warn you that it's really not secure at all to have a
connection string embedded in a DLL. Try it, then use Reflector
(http://www.aisto.com/roeder/dotnet/) to have a look at the assembly.

I agree it's more secure than a plain text file.

Quite how it should be secured depends on the app - it's usually not a
good idea to have a fixed password in the first place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #7
Ah yes, I haven't got my head round all this reflection and obuscation stuff
yet.
Security is not a major problem for me at the moment as it's only names and
addresses, but I still don't understand how you make the database behind a
web site really secure. (I don't understand what you mean by not having a
fixed password.) What are we actually securing against? - somebody manages to
download the asp and dll files (fairly easy) and the database (more difficult
because it's not in the URL's subtree). Then they dig the password out of the
dll (I thought DLLs were just binary, but I'll take your word that it can be
done) and open the database, bingo. So, we could put the database password in
an encrytped file, but it needs to be symmetrically encrypted as the app
needs to decrypt it, and the decrypt key will have to be built into the code,
so we're back to square one.
I'm obviously missing a trick here.
--
Dave
"Jon Skeet [C# MVP]" wrote:
Dave <Da**@discussions.microsoft.com> wrote:
I realised it was a stupid question shortly after I posted it. In actual fact
I would think that having the connection string embedded in the middle of a
compiled .dll was pretty secure - a good deal more secure than reading it in
plain text from another file (unless the file is encrypted of course).
I suspect that all the talk about securing the connection string is aimed at
scripted HTMl files, rather than compiled code-behind files. Nevertheless
when I create a dataconnection in ASP.NET I always get a warning asking if I
want to include the password in the connection string.
This whole security thing is a bit of a maze. Anyway, thanks for responding.


Just to warn you that it's really not secure at all to have a
connection string embedded in a DLL. Try it, then use Reflector
(http://www.aisto.com/roeder/dotnet/) to have a look at the assembly.

I agree it's more secure than a plain text file.

Quite how it should be secured depends on the app - it's usually not a
good idea to have a fixed password in the first place.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #8
Dave <Da**@discussions.microsoft.com> wrote:
Ah yes, I haven't got my head round all this reflection and obuscation stuff
yet.
Security is not a major problem for me at the moment as it's only names and
addresses, but I still don't understand how you make the database behind a
web site really secure. (I don't understand what you mean by not having a
fixed password.) What are we actually securing against? - somebody manages to
download the asp and dll files (fairly easy) and the database (more difficult
because it's not in the URL's subtree). Then they dig the password out of the
dll (I thought DLLs were just binary, but I'll take your word that it can be
done) and open the database, bingo. So, we could put the database password in
an encrytped file, but it needs to be symmetrically encrypted as the app
needs to decrypt it, and the decrypt key will have to be built into the code,
so we're back to square one.
I'm obviously missing a trick here.


Well, one way is to ask for the password when you install, and install
it using the Windows cryptography API which would let only the
appropriate user decrypt it. I'm afraid I don't know much about that
kind of thing, but that would be the idea.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #9

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

Similar topics

6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
5
by: David Mathog | last post by:
One thing that can make porting C code from one platform to another miserable is #include. In particular, the need to either place the path to an included file within the #include statement or to...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
6
by: tshad | last post by:
In my User control, I tried to do this: *************************************************************************** <Script runat="server"> Public ClientName As String = "<!-- #include file =...
2
by: yanksrock528 | last post by:
I am writing a program, and i would like to save an xml file that is on the internet now, to my computer in this csharp program. Something else that might help is if i could get the csharp xml...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.