Solved

VB App - Connection to SQL

Posted on 2006-07-19
2
213 Views
Last Modified: 2010-04-23
I have a VB.net that while in the development environment was connected up to a development database.  Now that the app is being moved to the production environment the connection has to changes.

Here is my problem:   All of the DataAdapters were created with the Wizard and that included the connection string.   There are 100's of adapters.

How can I change these?

If this were a web app I would have a reusable piece of code that would be called and the move to Production would only take a quick change to the connnection string in that code and not have to touch all the pages....is there the ability to do that in VB.net?

If I'm going to have to touch all the pages I'd rather add something like this rather than change the dbname.

Thanks in advance.
0
Comment
Question by:TimSweet220
2 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 500 total points
Comment Utility
Ahhhh, the benefits and drawbacks of the .NET wizards. This is why I create my adapters in code. My suggestion is to store your connection string someplace central and secure (ie., encrypted in the registry or in the App.Config file).

Then write a routine that will pull that string and then loop through all your adapters setting the Adapter.Connection property appropriately. Call this routine when your app initializes.

Or, alternatively, write a function that returns a Connection object (SQLConnection, ODBCConnection, or whatever type you have). The do a global search & replace for the ".Connection = " in your project and replace the connection information with your function. The end result for an adapter would look like this:

MyAdapter.Connection = GetConnection()

hope that helps.
0
 

Author Comment

by:TimSweet220
Comment Utility
Here is what I ended up doing.

Editing the appconfig file to like so:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
      <appSettings>
            <!--   User application and configured property settings go here.-->
            <!--   Example: <add key="settingName" value="settingValue"/> -->
            <add key="txbPGY.ReadOnly" value="False" />
            <add key="ColProgramYear.Text" value="Program Year" />
            <add key="ColProgramYear.Width" value="77" />
            <add key="ColStart.Text" value="Start Date" />
            <add key="ColCredit.Text" value="Credit" />
            <add key="ColVacDays.Text" value="Vac Days" />
            <add key="ColDateSent.Text" value="Date Sent" />
            <add key="ColTrain_Id.Text" value="Train_ID" />
            <add key="ColReference_Id.Text" value="Reference_ID" />
            <add key="SqlSelectCommand2.CommandText" value="dbo.[sp_GetRefData]" />
            <add key="ColRotationDesc.Text" value="Rotation Description" />
            <add key="ColWeeks.Text" value="Weeks" />
            <add key="ColEvaluation.Text" value="Evaluation" />
            <add key="ColTrainingYear.Text" value="Training Year" />
            <add key="ColTrainingType.Text" value="Training Type" />
            <add key="ColStartDate.Text" value="Start Date" />
            <add key="ColEndDate.Text" value="End Date" />
            <add key="ColumnHeader213.Text" value="TrackTitle" />
            <!-- Minime Connection -->
            <!--add key="ABRConn" value="workstation id=AD072;packet size=4096;user id=sa;data source=Production;persist security info=True;database=dbblah;password=blah" -->
            <!-- Smallme Connection -->
            <add key="ABRConn" value="workstation id=AD072;packet size=4096;user id=sa;data source=DEV;persist security info=True;initial catalog=dbblah;password=blah" />
      </appSettings>
</configuration>

then at the time of creating the build to distribute comment out the DEV source and UNcommenting the Production.

In the code we use this piece of code to set the connection

 'SqlConnection1
        '
        Me.SqlConnection1.ConnectionString = AppSettings.Get("ABRConn")



This works great.

however...it eliminates the use of the DataAdapter wizard because changes there remove the code in the above code InitializeComponent  - sure why.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now