.NET and SQL

G

Guest

Hello, I am a DBA at a company that is moving from VB 6 to the new .NET
environment. In our old VB6 environment connection strings were usually
embedded in the code. Things like server name, database, userid, password
were right in the VB6 code. This doesn't seem to good to me so I'm glad we
are moving away from that.

I have full access to the database servers but the developers own and manage
the web and application servers. From what I understand much of the sql
connection info on these servers is now contained in .NET config files. I
have yet to see one of these files but I would like to understand just what
these config files do (relating to connection strings, connection pooling
etc.). Can someone point me in the right direction so that I can get some
good, usable info on how .NET connects and accesses SQL server. Examples of
these config files and where they live would be helpful.

Thanks - Brad
 
S

Sahil Malik

Brad,

You can put connection strings in config files though nothing really
prevents you from putting them in code instead.

Config files are XML files that are named either web.config (for a web app)
or exename.config (for a windows app). You can put whatever settings you
wish in these, alongwith certain prespecified configuration settings that
come prebuilt with .NET. To learn more about config files, just look up
MSDN, or refer any good book but you would first have to choose your battle
between windows or web apps.

Specifically there is a lot more to .NET data access than configuration
files. There are plenty of ways to architect an application incorrectly -
even in .NET, so learning about ADO.NET alongwith .NET itself is critical.
You should also pick a good book on ADO.NET. I've written one, and there are
a few other good books in the market.

- Sahil Malik
You can reach me thru my blog http://www.dotnetjunkies.com/weblog/sahilmalik
 
M

Mike Labosh

Here's a snip:

In MyApp.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>

<!-- ADO.NET Connection String -->
<add key="connectionString"
value="Data Source=pc5197; Initial Catalog=Northwind; Integrated
Security=SSPI; Persist Security Info=False;"/>

</appSettings>
</configuration>

Now with that there, I can write code in my app that is protected aganst
connection string changes:

Import System.Configuration

Dim cnstr As String = _
ConfigurationSettings.AppSettings("connectionString")
Dim cn As New SqlConnection(cnstr)

So in this respect, the config file is an ini file; it just tastes like XML.
But since it's a human readable file via notepad, I wouldn't go specifying
login credentials in its connection string.

Also, for developers that are using the visual designers for their
connection objects (the component tray of a form, for example), if you set
the connection string property of a connection in there, if you use the
"Dynamic Properties" feature of the property window, it automatically puts
this in your config file for you.
--
Peace & happy computing,

Mike Labosh, MCSD

"It's 4:30 am. Do you know where your stack pointer is?"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top