|
I'm fairly new to VB.NET, (I was previously an ASP.NET develeper) and I have what a fairly trivial problem.
I am developing a system for a client where the application gets data from a SQL Server database. I have the connection string to the database stored in the app.config file. But the problem lies in that I am using a different database when developing than that which will be used on the live system. So it means that each time I build the project to test on their machines, I have to remember to change the connection string settings before I do so (and in fact, there are other settings like file paths which need changing to).
Like I said, a failry trivial isssue but if you guys have any suggestions on other ways to go about this then it would be appreciated.
Thanks.
|
|
|
|
|
I'd deploy a different app.config, or perhaps write code so that the debug version of your code reads one setting and the release, reads another. You do this with
#ifdef DEBUG
#else
#endif
in C#, I am not sure if VB is capable of that tho.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Couple of solutions:
1. Use two different connections settings, ex: devConnectionString and ProdConnectionString
2. Make a form that allows user to input settings such as db server name etc and save those settings.
|
|
|
|
|
You can consider something like this (change DEV_COMPUTER and TEST_COMPUTER to match the names of your computers):
<appSettings>
<add key="ConnectionString_DEV_COMPUTER" value="..." />
<add key="ConnectionString_TEST_COMPUTER" value="..." />
</appSettings>
ConfigurationManager.AppSettings("ConnectionString_" + Environment.MachineName).ToString
|
|
|
|
|
We allow the user to select the target server from a list when they logon. This then supports Dev/UAT/Production. Some of our apps will also have multiple scenario copies the user may need to use.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Good Morning All,
I have a question that I'm hoping someone out there maybe able to help me with. I'm trying to bind a CheckListBox to an Excel spreadsheet that has two columns of data. IPAddress & SystemName. I am new to programming and have only been able to get this fare. If anyone could help, you have my sincere thanks.
Tazy
Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;data source='C:\IPMonitoringTable.xls';Extended Properties=Excel 8.0"
Public Sub Retrieve_Records()
Dim conn As New OleDbConnection(m_sConn2)
Dim ExcelData As String
Dim i As Integer
conn.Open()
Dim da As New OleDbDataAdapter("Select IPAddress, SystemName, SysDate, SysTime, UserID from [IpAddrMonitor$]", conn)
Dim ds As DataSet = New DataSet
Try
da.Fill(ds)
CheckedListBox1.DataSource = ds
CheckedListBox1.DisplayMember = ds.Tables(0).TableName
'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work
'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This
Me.Refresh()
Catch OleDbExceptionErr As OleDbException
MsgBox(OleDbExceptionErr.Message)
End Try
conn.Close()
|
|
|
|
|
Tazy wrote: I am new to programming
Then why are you working on something this complex ? No-one is paying for your 'new to programming' code, are they ? If so, shame on you. If you're learning, choose something simpler to start with. You're just guessing here, and you'd do better to take a methodical approach to learning.
Tazy wrote: 'MsgBox(CheckedListBox1.Items(0).ToString) 'This didn't work
'MsgBox(CheckedListBox1.Items.Item(i).ToString()) 'Nor This
Well, a MsgBox is the wrong approach to take with ASP.NET anyhow, that will kill your server in a hurry. However, I assume this is debug code. Try instead to set a breakpoint. You'll find that the item is actually a DataRow, so you need to do Items(0)("SystemName"), or whatever.
In futurem don't say 'this didn't work', say 'this threw this excpetion', or 'this gave me a different result to what i hoped for, as follows... ', or 'this gave me the following compiler error.
And, for the love of all that is holy, buy a book and refer to it before asking questions. That's another step towards learning, towards actually becoming a programmer. People who take those sort of steps, are the sort of people we most like to help, because it doesn't feel like smashing your head against a wall.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
No I'm new on the job and just grad. from school and this is part of a project my boss has asked me to take over. I thought this would be easier then this and would make me look good, but school has prepared me enough for this type of project. But I also don't like to give up, so I keep trying. I don't want him to think that he hired the wrong person for the job.
|
|
|
|
|
OK - well, like I said, when you get an item from the items collection, it's a datarow, so you need to look up the data in the column you want to view from there. That's what the control does with the displaymember property.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
One error I spotted
Tazy wrote: CheckedListBox1.DisplayMember = ds.Tables(0).TableName
should be something like
CheckedListBox1.DisplayMember = "SystemName" (or whichever column you want to display)
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Good Morning Bob,
And once again Thx for your assistance. I tried your response will was given only:
"System.Data.DataViewManagerListItemTypeDescriptor" when running my program. Is there anything else I could try?
|
|
|
|
|
This is further proof that my answer is correct. Did you try what I suggested ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Sorry, didn't read the code fully.
Christian's reply is correct.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Is it possible to connect to any webserver through socket and receive the data using Socket?
Actually, I am developing one program which sends query to Google.com through socket and reads and dumps all the search results in a text file.
The parameters I have used in my program:
Dim client As New TcpClient("google.com", 80)
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes("search?q=codeproject")
Dim stream As NetworkStream = client.GetStream()
stream.Write(data, 0, data.Length)
' then read response and do stuffs
But I'm getting error like:
SocketException: System.Net.Sockets.SocketException: No connection could be made
because the target machine actively refused it
at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
Any idea why I'm getting this error?
"hi, I am explorer.exe. sometimes when you are doing anything at all, I will just freeze for ten minutes. All of my brother and sister windows will also freeze, because they are sad for me. Maybe we will come back, maybe not, it will be a surprise!"
|
|
|
|
|
Because you cannot. Use the httprequest and httpresponse classes instead.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks CG. Its working with httprequest.
"hi, I am explorer.exe. sometimes when you are doing anything at all, I will just freeze for ten minutes. All of my brother and sister windows will also freeze, because they are sad for me. Maybe we will come back, maybe not, it will be a surprise!"
|
|
|
|
|
hello all,
I'm a Asp.net developer and i know how to deploy a asp.net site with sql server database.
in asp.net website we just link with Remote server and deploy our database on that server.
but my question here is that while creating a window application in c# or vb if we have a database in sqlserver how we will deploy the sql sever database on every client machine individually.
is there any option in setup and deployment wizard. or we there is any other way.
Regards
Amit Agarwal
|
|
|
|
|
You wouldn't normally deploy sql server with an application, you normally have sql server running on a dedicated windows server on the network and clients connect to it, otherwise you have no single database for the company - each user has their won database, which doesn't make sense.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
There's no option. People generally deploy an Access DB if they can. Otherwise you need to deploy SQL Server Express, and code to create the database within it. This is a fair bit of work.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
hello guys
thanks for your reply.
but after googling i found that there are some options why which we can do this if you look at this forum reply..
http://bytes.com/forum/thread142240.html[^]
you will fnd out that Dan Guzman replied that
"Depending on your requirements, you can include the scripts in a .Net
project as either content files or as embedded resources. You can then
include that project in your Setup and Deployment project. Your custom
action can read and execute the scripts from either the resource assembly or from the file system"
this seems gud but i don't know how to achieve this.
and what about this Article:
http://www.codeguru.com/csharp/.net/net_security/encryption/article.php/c9601__1/[^]
Regards
Amit Agarwal
|
|
|
|
|
Basically it means you can deploy a program which creates the database. Which is what I was saying. The program still needs to run, and it need to find the DB, and run the scripts to create your tables, etc.
Access mdb files are easier.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: Access mdb files are easier.
What about SQL Express?
led mike
|
|
|
|
|
i have a form that allows the usere to add 0 to 4 contact numbers.
If tphone4 = "" And tphone3 = "" And tphone2 = "" And tphone1.Length > 0 Then
p.fAddPhoneNumber(contactId, phone1, tphone1)
ElseIf tphone4 = "" And tphone3 = "" And tphone2.Length > 0 And tphone1.Length > 0 Then
p.fAddPhoneNumber(contactId, phone1, tphone1)
p.fAddPhoneNumber(contactId, phone2, tphone2)
ElseIf tphone4 = "" And tphone3.Length > 0 And tphone2.Length > 0 And tphone1.Length > 0 Then
p.fAddPhoneNumber(contactId, phone1, tphone1)
p.fAddPhoneNumber(contactId, phone2, tphone2)
p.fAddPhoneNumber(contactId, phone3, tphone3)
Else
p.fAddPhoneNumber(contactId, phone1, tphone1)
p.fAddPhoneNumber(contactId, phone2, tphone2)
p.fAddPhoneNumber(contactId, phone3, tphone3)
p.fAddPhoneNumber(contactId, phone4, tphone4)
End If
above is my code. I just want to add the phone number if the text box(es) and dropdown box(es) ONLY has a data in it. also my code does not look right, any suggestions guys?
modified on Wednesday, June 25, 2008 3:11 AM
|
|
|
|
|
Yes, it's obviously wrong. Assuming that the user can't enter text in just tphone4, for example, you should start by checking 4, and work your way down. Otherwise you only ever store the first number. A better approach is to build a list of numbers from the four textboxes, then work out how many you have.
The other option is to check each pair individually, without the elseif. So, each one that has a pair of values, is stored, that seems the simplest solution. Why would you store phone1 b/c phone4 has a value ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
what i did was this:
If IsNothing(phone1) Then
phone1 = ""
Else
If tphone1.Trim.Length > 0 And phone1.Trim.Length > 0 Then
p.fAddPhoneNumber(klayentAydi, phone1, tphone1)
End If
End If
If IsNothing(phone2) Then
phone2 = ""
Else
If tphone2.Trim.Length > 0 And phone2.Trim.Length > 0 Then
p.fAddPhoneNumber(klayentAydi, phone2, tphone2)
End If
End If
If IsNothing(phone3) Then
phone3 = ""
Else
If tphone3.Trim.Length > 0 And phone3.Trim.Length > 0 Then
p.fAddPhoneNumber(klayentAydi, phone3, tphone3)
End If
End If
If IsNothing(phone4) Then
phone4 = ""
Else
If tphone4.Trim.Length > 0 And phone4.Trim.Length > 0 Then
p.fAddPhoneNumber(klayentAydi, phone4, tphone4)
End If
End If
basically it one by one checks the controls if there is data then adds it.
|
|
|
|