469,591 Members | 1,551 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,591 developers. It's quick & easy.

localhost or remote connection switch

Hello

I use a module to determine whether SQL connection is to my localhost or to
my remote server. At moment, I enable either one or the other line of code
to switch between, then build, (then upload if publishing to remotre
server).

Trouble is, I'm forever forgetting to do the switch/build before uploading
so have to re-upload. Any suggestions as to how program can automatically
determine which code line to use? Try/Catch no good in module. Neither have
I had success with server.mappath.

Thanks
Graeme
Nov 21 '05 #1
5 1522
Saladin,

I think that this is a little bit difficult to do.

In testing situations you want probably the local connection
In production situations you want probaly the remote connection.

How should the computer know if you are testing or that you are running
production?

The advance from putting the string encrypted outside your program is that
you can change it without to rebuild your complete program. You have than to
build of course a seperate program to build that encrypted
connectionstringfile.

I hope that this gives some idea's

Cor
Nov 21 '05 #2
For test purposes I use the #if DEBUG preprocessor directive to deliver the
connection strings etc for my local host configurations. The release version
has the live server. The code below shows the principle.

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

components = New System.ComponentModel.Container()

Me.Text = "Form1"

End Sub

#End Region

#If DEBUG Then

Sub foo(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

MessageBox.Show("DEBUG")

End Sub

#End If

#If Not Debug Then

Sub foo(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

MessageBox.Show("RELEASE")

End Sub

#End If

End Class
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Saladin" <ma****************@wave.co.nz> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
Hello

I use a module to determine whether SQL connection is to my localhost or
to
my remote server. At moment, I enable either one or the other line of code
to switch between, then build, (then upload if publishing to remotre
server).

Trouble is, I'm forever forgetting to do the switch/build before uploading
so have to re-upload. Any suggestions as to how program can automatically
determine which code line to use? Try/Catch no good in module. Neither
have
I had success with server.mappath.

Thanks
Graeme

Nov 21 '05 #3
To determine the data path to use in a connection string, I check for some
text that would be in the path on my development string but not in the path
at the web site.

Here is a typical example

Dim DataPath As String
If InStr(Server.MapPath("."), "Text to be found on Dev. server",
CompareMethod.Text) = 0 Then
DataPath = Server.MapPath(".") & "\MyData\MyDatabase.mdb"
Else
DataPath = Server.MapPath(".").Substring(0,
InStr(LCase(Server.MapPath(".")), LCase("\Services"), CompareMethod.Text)) &
"MyData\MyDatabase.mdb"
End If

The web Folder structure is as follows with the database inside the MyData
folder.

Web site
Bin
MyData
Services

"Saladin" <ma****************@wave.co.nz> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
Hello

I use a module to determine whether SQL connection is to my localhost or
to
my remote server. At moment, I enable either one or the other line of code
to switch between, then build, (then upload if publishing to remotre
server).

Trouble is, I'm forever forgetting to do the switch/build before uploading
so have to re-upload. Any suggestions as to how program can automatically
determine which code line to use? Try/Catch no good in module. Neither
have
I had success with server.mappath.

Thanks
Graeme

Nov 21 '05 #4
Thanks Guys. I'll spend some time and see what I can do.
"Saladin" <ma****************@wave.co.nz> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
Hello

I use a module to determine whether SQL connection is to my localhost or
to
my remote server. At moment, I enable either one or the other line of code
to switch between, then build, (then upload if publishing to remotre
server).

Trouble is, I'm forever forgetting to do the switch/build before uploading
so have to re-upload. Any suggestions as to how program can automatically
determine which code line to use? Try/Catch no good in module. Neither
have
I had success with server.mappath.

Thanks
Graeme

Nov 21 '05 #5
Thanks Guys. I'll spend some time and see what I can do.
"Saladin" <ma****************@wave.co.nz> wrote in message
news:e1**************@TK2MSFTNGP10.phx.gbl...
Hello

I use a module to determine whether SQL connection is to my localhost or
to
my remote server. At moment, I enable either one or the other line of code
to switch between, then build, (then upload if publishing to remotre
server).

Trouble is, I'm forever forgetting to do the switch/build before uploading
so have to re-upload. Any suggestions as to how program can automatically
determine which code line to use? Try/Catch no good in module. Neither
have
I had success with server.mappath.

Thanks
Graeme

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Red Golpe | last post: by
2 posts views Thread by Jeff | last post: by
12 posts views Thread by Jonathan Wood | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.