473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1662
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
connectionstrin gfile.

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.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() 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.Disp ose()

End If

End If

MyBase.Dispose( disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.Componen tModel.IContain er

'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.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()

components = New System.Componen tModel.Containe r()

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******** ******@TK2MSFTN GP10.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.Ma pPath("."), "Text to be found on Dev. server",
CompareMethod.T ext) = 0 Then
DataPath = Server.MapPath( ".") & "\MyData\MyData base.mdb"
Else
DataPath = Server.MapPath( ".").Substring( 0,
InStr(LCase(Ser ver.MapPath("." )), LCase("\Service s"), CompareMethod.T ext)) &
"MyData\MyDatab ase.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******** ******@TK2MSFTN GP10.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******** ******@TK2MSFTN GP10.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******** ******@TK2MSFTN GP10.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
2216
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 "http://..." it doesn't work any more. Any suggestion? Red Golpe ______________________________________________ "What does not kill you......
4
8404
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 conn As ADODB.Connection Dim cs As String Dim MyServer As String
2
2287
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 are hosted by a third party (on separate servers). Since debug mode opens IE and loads my page from localhost, since the database is located at a...
3
4308
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 #1 MSSQL 2000 sp4 Windows 2000 Server PHP4 on IIS5 (CGI)
6
3617
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 list of all of my webs, however if I attempt to open a site under and web other than localhost I receive the message: "Unable to open the Web...
6
9982
by: Varlamov Konstantyn | last post by:
I have simple script: <?php $connection = ssh2_connect("ip", 22); ssh2_auth_password($connection,"login","test");
8
2826
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 put into stand-by or hibernation 3. later, computer is brought out of stand-by or hibernation 4. when trying to save or close form, SQL exception...
5
3539
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 this error. Any idea why? Server Error in '/myuser4/MyWebApp' Application....
12
2353
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 Connection software. Everything is working just fine. However, whenever I run an ASP.NET Website project in Visual Studio, the browser pops up a...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.