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

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 1649
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Red Golpe | last post by:
I've managed to read from a local database using only javascript and the DAO ActiveX object, but I can't make it work with a remote database. When I change the connection string from "C:\..." to...
4
by: Ian Davies | last post by:
Hello all The following code allows me to connect to a local MySQL database on my pc from a VB6 project. **************************************************************************** ** Dim...
2
by: Jeff | last post by:
Hi - I have an ASP.NET web page accessing a SQL database. It works fine on the web, and I'm trying to get it to also work in debug mode in the IDE. The "on the web" page and my SQL database...
3
by: gharmel | last post by:
I'm trying to get some clues on why I get (much) slower responses from my PHP applications when dealing with a remote sql server as opposed to a local sql server. Here's my situation: Server...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
6
by: Varlamov Konstantyn | last post by:
I have simple script: <?php $connection = ssh2_connect("ip", 22); ssh2_auth_password($connection,"login","test");
8
by: BD | last post by:
I am developing C# win form app to work with remote database on SQL Server 2005. Problem scenario is as follows: 1. a form is open that has downloaded dataset to local cache 2. computer is...
5
by: Cirene | last post by:
I just deployed my new ASP.NET (3.5 FW) site to the hosting company I'm using, webhost4life. NOTE: I HAVE deployed other SQL Server sites to the same account with no issues. Now I'm getting...
12
by: Jonathan Wood | last post by:
Greetings, I wonder if anyone can help me with this. I have an XP laptop, and a Vista desktop computer. I use the laptop to run software remotely on the desktop using the Remote Desktop...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.