|
The is no way for TCP to recognize that the other end no longer exists when it is waiting for a response.
So the same is true for any protocol built on it.
There might be situations where some sort of exception results. Maybe. For example I am not sure what the windows IP stack might do if you pull your network cable.
But if you want to deal with all situations and not a just a few then you need to set up a timeout. Either via the protocol itself or via a secondary thread.
|
|
|
|
|
jschell wrote: But if you want to deal with all situations and not a just a few then you need
to set up a timeout. Either via the protocol itself or via a secondary thread
I do set timeout in web request but I do not know how to set it for Read() operation as it just blocks.
Чесноков
|
|
|
|
|
Hello,
Instead of on the aspx page, to have this code on the server side. Can we do this? Especially for the email check and decimals check? Like for the email check i have this set up on the page aspx, \w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*? Can add it the same way on the server page, meaning .cs page?
Thanks!
|
|
|
|
|
Do you mean add a RegularExpressionValidator control to the page from the code-behind? If so then yes.
RegularExpressionValidator validator = new RegularExpressionValidator();
validator.ValidationExpression = "...";
Controls.Add(validator);
If you mean can you valid a string in the code-behind, then again yes.
Regex.IsMatch("pattern", stringToCheck);
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I tried Regex but it was not showing as an option. I will try using RegexStringValidator.
Thanks for your help in a timely manner!
|
|
|
|
|
vanikanc wrote: I tried Regex but it was not showing as an option
What are you talking about? Do you have the correct assemblies referenced? Do you place the correct using statement?
RegexStringValidator is not what you need to use. It will throw an exception if the string is not correct, very heavy handed and not recommended.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I have
using System.Configuration;
anything else?
|
|
|
|
|
|
hello guys.. a basic question about inserting row in the sql server. I made all the necessary arrangements first (like creating a login then enabling it, changing the login mode to Mix-Mode). But following code is not working, I dont know what is the problem in the connection string
string connectionString = "Data Source=srv032k3; Initial Catalog=MuzeDB;Integrated Security=SSPI; User ID=sa; Password=;sa";
SqlConnection connection = new SqlConnection(connectionString);
try
{
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM students ORDER BY Id", connection);
SqlCommandBuilder command = new SqlCommandBuilder(adapter);
DataSet ds = new DataSet("StudentsSet");
adapter.Fill(ds, "students");
DataTable dt = ds.Tables["students"];
DataRow row = dt.NewRow();
int id;
string name, address;
id = 4;
name = "Nadeem";
address = "Layya";
row["Id"] = id;
row["Name"] = name;
row["Address"] = address;
dt.Rows.Add(row);
adapter.Update(ds, "students");
Console.WriteLine("A new row added: {0} {1} {2}", id, name, address);
connection.Close();
}
catch (Exception ex)
{ Console.WriteLine(ex.Message); }
what can be the problem? thnx
|
|
|
|
|
Well, you have password=;sa . That's the problem - the ; tells it that you have an empty password, and then the sa creates a malformed connection string.
|
|
|
|
|
I did what you suggested but it is not working (using a different login). Here is modified connection string
string ConnectionString = "Data Source=srv032k3;Initial Catalog=MuzeDB;Integrated Security=SSPI; User ID=muze; Password=saeedasd;";
|
|
|
|
|
As you have a user name and password, you need to remove Integrated Security=SSPI; . It's one or the other, not both.
|
|
|
|
|
Hi,
Try to remove Integrated Security=SSPI; from your connection string. You are trying to use two connection methods at the same time (SSPI means you're trying to authenticate as the calling user, and you provide other authentification information at the same time).
Moreover, it's a very bad design to authenticate as 'sa' in your code ; better create a connection in your SQL instance matching your user login, and give it the roles you want on the database(s) you want. Then you'll be able to use Integrated Security=SSPI; , without supplying UserId and Password information in your connection string.
|
|
|
|
|
I did what you suggested but it is not working. Here is modified connection string
string ConnectionString = "Data Source=srv032k3;Initial Catalog=MuzeDB;Integrated Security=SSPI; User ID=muze; Password=saeedasd;";
|
|
|
|
|
No you didn't. Read carefully and you will get it.
|
|
|
|
|
Yes. I did it. I actually made a new login and then tried to used that connection string. Does this mean that either I should use Integrated Security or I the User ID, Password methodology?
|
|
|
|
|
Yes, it is exactly what that means
|
|
|
|
|
Try
string connectionString = "Data Source=srv032k3; Initial Catalog=MuzeDB; User ID=sa; Password=YourPassword";
take a look there[^]
for more information.
|
|
|
|
|
You're also creating an adapter from a select statement. Is it possible to insert through that? That seems a bit weird to me.
|
|
|
|
|
Yes. I have done it. It adds a new row and it also selects all records from the table and puts them into the dataset.
|
|
|
|
|
hello everyone,
I want to calculate the total data download and upload in a particular interval of time, and store it to a database so that it can be viewed later on. data downloaded from internet
browser or uploaded using default downloader and i want to store info - size and time
info. is it possible through system.diagnostics namespace........
thank you for any help...........
|
|
|
|
|
I have created an XML using sql in SQL Server 2005.
I like to Save that XML as a File in a particular location on the disk.
I want only C# to make it done...
It would not be possible to create that file on the disk using SQL Server becoz,
I haven't administrator permission for the Sql Server.
if i use DataReader to get field value, than it's not return complete xml...
what i have to do...?
|
|
|
|
|
|
Presumably you are not asking how to create a file on the SQL Server file system itself given that you do not have access to that file system. So....
Steps
1. Connect to SQL Server
2. Query for xml
3. Open file
4. Read xml
5. Write xml to file.
6. Continue 4 and 6 until all of the xml is read.
7. Close the connection and the file.
The above are distinct parts of the total problem.
|
|
|
|
|
Hi.
I want to make a program to download files from a remote host.
So what i do is to send throw sockets all the binary information + a string used as end "mystyring".
To check if i have to continue writing the buffer to the file i first convert all to string, so if i find "mystring" it will finish, if not, i reconvert all to bytes and i copy data.
The problem im having is that, .txt files are writed well, but binaris not, it always show error at opening. I ve tried copying a pdf, and when i open it show all the pages, but in blank . Also if i check the size of the original file is always some bytes bigger than the copy.
FileStream fs = new FileStream("C:\\Users\\Mauri\\Desktop\\" + item.Name, FileMode.Append, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
bool continua = true;
while (continua)
{
recibido = getSocket(numsock).socketRecv();
words = recibido.Split('|');
foreach (string s in words)
{
if ((String.Compare(s, "mystring") != 0))
writer.Write(StringToBytes(s));
else
continua = false;
}
}
writer.Close();
fs.Close();
public byte[] StringToBytes(String cadena)
{
System.Text.ASCIIEncoding codificador = new System.Text.ASCIIEncoding();
return codificador.GetBytes(cadena);
}
The strange thing is that .txt files are writed correctly.
I can't use webclient class, beacuse im not downloading the data from an http or ftp server, is for a connection between 2 computers, like a remote access program.
Thanks
|
|
|
|