473,378 Members | 1,510 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,378 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 2206
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.