Click here to Skip to main content
15,895,084 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Input CAPS letters in textbox Pin
tjkota28-Aug-07 11:38
tjkota28-Aug-07 11:38 
GeneralRe: Input CAPS letters in textbox Pin
Fred_Smith28-Aug-07 11:50
Fred_Smith28-Aug-07 11:50 
GeneralRe: Input CAPS letters in textbox Pin
Christian Graus28-Aug-07 13:34
protectorChristian Graus28-Aug-07 13:34 
GeneralRe: Input CAPS letters in textbox Pin
tjkota28-Aug-07 13:36
tjkota28-Aug-07 13:36 
QuestionUse different web.config for debugging Pin
error140828-Aug-07 8:31
error140828-Aug-07 8:31 
AnswerRe: Use different web.config for debugging Pin
nateraaaa28-Aug-07 8:51
nateraaaa28-Aug-07 8:51 
GeneralRe: Use different web.config for debugging Pin
error140828-Aug-07 8:53
error140828-Aug-07 8:53 
AnswerRe: Use different web.config for debugging [modified] Pin
Fred_Smith28-Aug-07 9:05
Fred_Smith28-Aug-07 9:05 
I never understand why people save their connection strings in web.config... how unsecure is that?

This is how I avoid your problem:

1) In global.asax I have a function like this:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
Select Case Server.MachineName.ToLower
Case "aaaaa"
' local
Application("ServerName") = "local"
Case "bbbbb"
' laptop
Application("ServerName") = "laptop"
Case Else '
' live
Application("ServerName") = "live"
End Select
End Sub

You will need to find out, if you don't know already, your local machines name. User Server.MachineName in any aspx page to find out if you need to.

2) I then make a publicly available function such this:

Public Class myFunctions

Public Function dbConnection(ByVal ServerName As String) As String
Select Case ServerName
Case "live"
Return "data source=xxxxx;initial catalog=xxxxx;uid=xxxxx;pwd=xxxxx"
Case "local"
Return "data source=yyyyy;initial catalog=yyyyy;uid=yyyyyy;pwd=yyyyyy"
Case "laptop"
Return "data source=zzzzzz;initial catalog=zzzzz;uid=zzzzz;pwd=zzzzz"
End Select
End Function

End Class

3) Then I can use the same code throught my app to connect to the database on whateve computer I am running on:

Dim myFunction As New myFunctions
Dim objConn As New SqlClient.SqlConnection
objConn.ConnectionString = myFunction.dbConnection(Application("ServerName"))

Works a treat!


-- modified at 15:11 Tuesday 28th August, 2007

Of course, you don't acually need to use the Application object at all, but could call the function directly with

objConn.ConnectionString = myFunction.dbConnection(Server.MachineName)

if you replaced the Select..Case in the dbConnection function with the amchine names there instead of the aliases I created. But there was a reason I did it this way when I first came up with it - just can't remember what it was now! - and I have always done it the same way since!

Fred

Questionhandle imagebutton click in gridview Pin
ChrisFarrugia28-Aug-07 5:29
ChrisFarrugia28-Aug-07 5:29 
AnswerRe: handle imagebutton click in gridview Pin
nateraaaa28-Aug-07 7:58
nateraaaa28-Aug-07 7:58 
QuestionHow to use LDAP Authentication. Pin
somagunasekaran28-Aug-07 4:13
somagunasekaran28-Aug-07 4:13 
AnswerRe: How to use LDAP Authentication. Pin
Michael Sync28-Aug-07 18:50
Michael Sync28-Aug-07 18:50 
Questioncomponent chart in asp net 1.0 Pin
raquidd2228-Aug-07 4:08
raquidd2228-Aug-07 4:08 
QuestionInsert ASP.NET script in HTML Pin
CodeItWell28-Aug-07 3:57
CodeItWell28-Aug-07 3:57 
AnswerRe: Insert ASP.NET script in HTML Pin
ChrisFarrugia28-Aug-07 5:32
ChrisFarrugia28-Aug-07 5:32 
QuestionDeploying an asp.net 2.0 running on IIS 6.0, on Windows vista?? Pin
Nada Adel28-Aug-07 3:27
Nada Adel28-Aug-07 3:27 
AnswerRe: Deploying an asp.net 2.0 running on IIS 6.0, on Windows vista?? Pin
DigiOz Multimedia28-Aug-07 8:12
DigiOz Multimedia28-Aug-07 8:12 
GeneralRe: Deploying an asp.net 2.0 running on IIS 6.0, on Windows vista?? Pin
Nada Adel28-Aug-07 8:32
Nada Adel28-Aug-07 8:32 
GeneralRe: Deploying an asp.net 2.0 running on IIS 6.0, on Windows vista?? Pin
DigiOz Multimedia28-Aug-07 8:38
DigiOz Multimedia28-Aug-07 8:38 
Questiondropdownbox contain all the values want to store..., Pin
Member 387988128-Aug-07 3:22
Member 387988128-Aug-07 3:22 
AnswerRe: dropdownbox contain all the values want to store..., Pin
nateraaaa28-Aug-07 7:06
nateraaaa28-Aug-07 7:06 
Questionretriving images Pin
diwa8528-Aug-07 3:15
diwa8528-Aug-07 3:15 
GeneralRe: retriving images Pin
Kunal P28-Aug-07 18:46
Kunal P28-Aug-07 18:46 
QuestionException Handling Pin
rockyl28-Aug-07 3:14
rockyl28-Aug-07 3:14 
AnswerRe: Exception Handling Pin
StylezHouse28-Aug-07 3:19
StylezHouse28-Aug-07 3:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.