It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to show one detail_report page of my web application which is hosted on server.
We have used asp.net to create that application.
I have following list to show on detail_page
Host Name
Host Date/Time
Database Status
Build Version
Build Timestamp
I'm really trying to get Database Status using Ping but unable to do that.
anyone can help me I need to use asp.net + C#
Why do you need to ping database in order to get status of database?
Just handling the sql connection exception in your application will be enough to show the related information on server status. In addition to the exception handling, when your DB is down, you may also use connection string information to display the DB name, and other information from resource files like web.config.
However, i hope you don't have plans to display username and password of the connection string to your users :)
You may try doing something like this. Hope this helps.
public void displayDBDetails()
{
SqlConnection sqlConn = new SqlConnection(string yourConnectionString);
sqlConn.Open();
string dbName = sqlConn.Database.ToString();
string dbStatus = sqlConn.State.ToString();
string dbServerVersion = sqlConn.ServerVersion.ToString();
etc.....
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am a student and working on winform c#. I have a small app and I want to add a new feature of memo reminder. For example, when I type something in a text box, the app saves it and set a timer of 8 hours. If the app is running, then a message should popup with the message I have saved.
It's not clear to me if I should use a database for reminding the entries or something else provided by c#. As far as I know all thing are automated. Is there anything which will help me to build this functionality, like a timer??
Store somewhere in the txt file if using database is not possible.
Like this:
3.20.2013 11:20:00 | Remind me something.
Then your timer checks every minute or so.
UPDATE:
Example:
DateTime savedTime = Convert.ToDateTime("date from the text file");
if(DateTime.Now >= savedTime)
{
MessageBox.Show("reminder from the text file");
}
UPDATE2:
string pathToStoreTXT = Application.UserAppDataPath;
pathToStoreTXT has the path something like: "C:\Users\UserName\AppData". Your timer need's to check for that folder all the time. Name your txt file like "MyReminders.txt".
Simple flow would be:
When app is run, check if file is created or not. This file will store your data!
Check if there is any record in the file or not.
2a. Show expired messages and clear them too.
Add timer like Dilshod has suggested.
3a. Convert reminder datetime as timestamp and concatenate it with message to store in text file
Create at a timer object with tick event every 1 minute, something like this. (Obviously you will need to set frequency which is passed as parameter)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a field that's stored in the database as a string. It's actually a comma-separated string of numbers that I convert to a list of longs. The lines of code that do the conversion look somewhat like this:
TheListOfLongs = (from string s in StringFromDB.Split(',')
select Convert.ToInt64(s)).ToList<long>();
The code that creates the database storage string looks like this:
return String.Join(",", TheListOfLongs.Select(x=> x.ToString()).ToArray());
This works fine but as you can see, if for some reason there's a problem with the string, the code in the first line of code breaks on Convert.ToInt64(s).
Now I know I can wrap all this around a try statement but my question is this: can storing and retrieving a string in the database corrupt the string (in which case I definitely need the try statement) or is this a one a trillion odd type of event?
I wouldn't worry about corrupt data per se. However, you definitely need to handle the more general case where you can't parse what should be numeric data.
Even in the most controlled situations it is good programming practice to provide conditions for when you can't process data as you're expecting to be able to. What that means to your application is something you'll need to decide. Wrapping the statement with a try..catch will prevent your application from choking, but may not be appropriate if the parsed list is critical later on.
Selecting from the DB shouldn't corrupt your string.
If the connection is dropped mid transfer or something like that then an exception is thrown.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I don't know how to put the title but i will try to explain it the requirement here.
Normally user entered an URL in address bar in browser, for example www.example.com, then click a link and redirect to another page www.example.com/test.aspx. Alternatively, user also can just enter/type www.example.com/test.aspx from address bar if they know the full path.
So, i required to write a code where user can type an URL in address bar, for example www.example.com/test.aspx?usr="www.test.com". (note: with addition usr="www.test.com")
The "usr="www.test.com" after www.example.com/test.aspx? contain a value that stored in database.
So, when the user type www.example.com/test.aspx?usr="www.test.com" it will search the database for matching www.test.com and do some process if found.
How can i achieve this.
You have to use Request.QueryString to get value any param passed to the page.
The result, stored in a page variable, can be used to retrieve the needed data.
string usr = Request.QueryString["usr"];
You can get the values in url after ? from HttpContext using
string url = HttpContext.Current.Request["usr"];
If the value is being passed through in the query string (the part after the '?'), you can just check for it using the Request object.
C#
string url = HttpContext.Current.Request["usr"];
// Then perform your search based on the value in URL.
Note: You can also use string url = HttpContext.Current.Request.QueryString["usr"]; if you want to ensure that your value of usr is only from the query string and not a POST or COOKIE. See here for further info.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to create a folder automatically when a solution is installed in the computer i.e( Local Disk:D) using c# windows forms?
Solution#1:
On first run of the application (make an xml file to track the first execution) you may create folder.
Solution#2: (Good one)
You may check if that directory exists ,if not then create the directory
try
{
// If the directory doesn't exist, create it.
if (!Directory.Exists(palettesPath))
{
Directory.CreateDirectory(palettesPath);
}
}
catch (Exception)
{
// Fail silently
}
Source:
check this link
How to Add Items to a Deployment Project
http://msdn.microsoft.com/en-us/library/z11b431t.aspx
Specifically:
How to: Add and Remove Folders in the File System Editor
http://msdn.microsoft.com/en-us/library/x56s4w8x.aspx
See the MSDN for more info, but the gist is:
You set the path like either of the ways below. See string literals for more info on this:
string newPath = #"c:\yourpath";
or
string newPath = "c:\\yourpath\\morepath";
To create the directory, you use this:
System.IO.Directory.CreateDirectory(newPath);
Hope this helps!
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
if you please help me out i am trying to pass 3 different parameters in a page but i am new in asp.net C# and i don't know the correct syntax if you please help me out
;
For one parameter like this it works:
Response.Redirect("~/WebPage2.aspx?q=" + ListBox1.SelectedValue);
how can i write it for 3 parameters like this don't seem to work?
Response.Redirect("~/WebPage2.aspx?q=" + ListBox1.SelectedValue+"&cr="+ListBox3.SelectedValue+"&p="+ListBox1.SelectedValue)
thanks in advance
You forgot a + in your string concatenations after the cr parameter. This being said a far safer and better approach which ensures that your parameters are properly encoded is the following:
var parameters = HttpUtility.ParseQueryString(string.Empty);
parameters["q"] = ListBox1.SelectedValue;
parameters["cr"] = ListBox3.SelectedValue;
parameters["p"] = ListBox1.SelectedValue;
var url = string.Format("~/WebPage2.aspx?{0}", parameters.ToString());
Response.Redirect(url);
And of course if you are using ASP.NET MVC (as you've tagged your question with it) you would use:
return RedirectToAction("SomeAction", new {
q = ListBox1.SelectedValue,
cr = ListBox3.SelectedValue,
p = ListBox1.SelectedValue
});
I very sincerely hope that if you are using ASP.NET MVC then ListBox1 and ListBox2 is not what I think it is.
Here's what I typically do (assuming a constant number of parameters for each URL):
string url = "~/WebPage2.aspx?q={q}&cr={cr}&p={p}";
url = url.Replace("{q}", ListBox1.SelectedValue)
.Replace("{cr}", ListBox2.SelectedValue)
.Replace("{q}", ListBox3.SelectedValue);
Response.Redirect(url);
I have not tested it, but this may be relatively inefficient. The reason I do it this way is so I know exactly what the URL pattern looks like and which parameters are used.
It's a trade-off to be sure, and am curious to see other peoples' feedback.