|
Ah, I think I might see the issue.
The Read function is a little funny on streams. It only guarantees that you will get some data back, but not how much. You are doing the right thing by checking the return value of Read and incrementing len - forgetting to do this is actually a common mistake you see in real-life programs.
When you are writing to your file, you need to only write how much data you read.
Say your read function reads in 500 bytes...
Notice the line
fsout.Write(buffer, 0, buffer.Length);
Even though you only read 500 bytes, you're writing out 1024 (buffer.Length)! You need to only write out to the file however much you read in. Fix that line, and I'll bet your program works without the need for doing thread sleeps.
|
|
|
|
|
Thank you m8 what was good help .
|
|
|
|
|
Yes, don't call BeginReceive again until you are finished with the data returned, or if you do provide a different offset.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
If you don't ask questions the answers won't stand in your way.
Most of this sig is for Google, not ego.
|
|
|
|
|
hi every one,
I'm trying to connect to a database in SQL server 2005 from a c# application. My goal is to use SQL Authentication using a user id and a password. My problem is in sql server side where I'm trying to work with logins, users, roles, schemas, etc.
Further more is it possible to deploy the applicatin with sqlExpress so that no one could access the database except for the application using it?
thnx
|
|
|
|
|
If SQLExpress is installed on the machine, I don't see how unless you consistently encrypt the database.. You can control decrypting through your application to decrypt records on the fly but that might be slightly inefficient depending on what you are doing. Check into obfuscation for a broad range to start securing your code, and .Net has a lot of encryption related classes so you can learn how to store your data on a database to prevent people from snooping.
|
|
|
|
|
Hi guys, I am wondering if there is a way to add a RadioButtonList inside the Listview control. Currently, my Listview checkboxlist is behaving like a radio button. But I want to change its look so its UI looks appealing.
Thanks
|
|
|
|
|
I dont think what you want is easily done, would have to be with some paint event coding.
The best thing would prob be a custom control, wouldnt be too hard for your requirements
My opinion is... If someone has already posted an answer, dont post the SAME answer
|
|
|
|
|
Check out the RadioButtonRenderer class
|
|
|
|
|
Hi all,
Could you please help me how to access a database from the following config file(web config).
<configuration>
<sqlserver>SERVER_BMRD</sqlserver>
<sqldatabase>B</sqldatabase>
<sqluser>BD_user</sqluser>
<sqlpassword>^1^vtqhCBOwbVJc+ODAe2Sm7A==</sqlpassword>
<sqltrusted>False</sqltrusted>
</configuration>
How will i be able to connect to the above database?
For example :
SqlDataAdapter sda = new SqlDataAdapter("Stored_procedure", Connectionstring);
Can you give me how my connection string should look like?
Thank you so much
|
|
|
|
|
|
Thanks for your response Rob.
It was given to me as a database credentials to be able to connect to the database.
You can see that they dont use connection string ?so that is my problem
How can i connect to a database using those credentials?
Regards,
kibrom
modified on Monday, February 9, 2009 12:23 PM
|
|
|
|
|
OK, to my knowledge that won't be easy. Config files have to follow a certain format, and you define sections when you want to implement your own settings. Just placing individual bits in there like that will likely cause the ConfigurationManager to protest.
Your app.config file is invalid. As such, the best bet would be to bypass the ConfigurationManager altogether and process the file as any other xml file. One such way would be to use an XmlDocument and retrieve the settings using XPath.
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob ,
Thank you so much for your help.Sorry as i am new to this could you please give me a tip on how to use it with XMLReader or XMlDocument?
Thanks a lot.
|
|
|
|
|
Sure. I'm just about to leave work now, so I'll put something together in a couple of hours once home. A few things to check - this file is called web.config and resides in the usual place with your application?
Also, you absolutely cannot change the format of this file? A simple inclusion of appSettings would make this a breeze.
I'd create a class which reads this file and then exposes each setting you need as a public string property. If I remember correctly the ASP.NET world watches web.config and updates automatically - you wouldn't get that with this approach.
More later...
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob,
Your help is Much appreciated Rob.Yes please its a config file.But its not a webconfig file.For instance the above can be called admin.config file.
The file doesnt have app setting? we can still include appSettings.However they dont have it in this file.
Thanks again for your time.
|
|
|
|
|
The class below should do what you want, create a new instance passing in the config file as the parameter to the constructor.
public class DatabaseConfiguration
{
public readonly string SqlServer;
public readonly string Database;
public readonly string User;
public readonly string Password;
public readonly bool Trusted;
public DatabaseConfiguration(string path)
{
XmlDocument settings = new XmlDocument();
settings.Load(path);
SqlServer = settings.SelectSingleNode("/configuration/sqlserver").InnerText;
Database = settings.SelectSingleNode("/configuration/sqldatabase").InnerText;
User = settings.SelectSingleNode("/configuration/sqluser").InnerText;
Password = settings.SelectSingleNode("/configuration/sqlpassword").InnerText;
Trusted = settings.SelectSingleNode("/configuration/sqltrusted").InnerText.ToLower() == "true";
}
}
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob,
You are a champion,thanks a lot.I have done it like you said.
Sorry one more question, Can you give me an example on how to execute a stored procedure with the class.
Like for instance :-
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("Test", ???????????????);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.Add("@timeInStart", SqlDbType.DateTime);
sda.SelectCommand.Parameters["@timeInStart"].Value = from;
sda.SelectCommand.Parameters.Add("@timeInEnd", SqlDbType.DateTime);
sda.SelectCommand.Parameters["@timeInEnd"].Value = to;
sda.Fill(ds);
????????- This is a place for connection string? How do i go about that?
Thanks a lot Rob
|
|
|
|
|
Well, your connection string should look like this (from connectionstrings.com):
Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password=myPassword;Trusted_Connection=False;
So, add a new string property to the class and construct that string using what you have. That's what you want for ?????????.
eg:
public string ConnectionString
{
get
{
return string.Format("Server={0};Database={1};User ID={2};Password={3};Trusted_Connection={4};", SqlServer, Database, User, Password, Trusted ? "True" : "False");
}
}
Regards,
Rob Philpott.
|
|
|
|
|
Hi Rob,
Thanks very much.Can we connect to the database with out using the connection string?
Just with the class you have given me? Can you give me just an example.
Sorry i am taking you time.
Thanks Rob
|
|
|
|
|
Yeah, you could add some functionality to that class which returns a valid open connection, and just use that as the connection
Something like:
public SqlConnection CreateConnection()
{
SqlConnection connnection = new SqlConnection(ConnectionString);
connection.Open();
return connection;
}
Remember to use the connection in a using bloke or call its dispose when you are done with it.
Regards,
Rob Philpott.
|
|
|
|
|
Do you think this should work to execute a stored procedure.
SqlDataAdapter sda = new SqlDataAdapter("Stored_proce", DatabaseConfiguration.connectionstring);
or simply use
SqlDataAdapter sda = new SqlDataAdapter("Stored_proce", DatabaseConfiguration.createConnection
I hope this will definely sort me out.
Thanks a million Rob.
|
|
|
|
|
I think you can use the first approach. Personally I'd create a connection, then create a command, then attach the adapter to that but its just personal preference.
You can reuse your connection if doing lots of things that way.
Regards,
Rob Philpott.
|
|
|
|
|
Thank very much for your help Rob.I will keep you posted.
Many thanks
|
|
|
|
|
Hello everybody
I am a real beginner in C# programming language.
I have a binary file, with binary data (ok). I would like to find a specific string in the file and make calculation of the found values.
Example: In the binary file, I have : "#{'"éé&$$¨DATAFOUNDllolml"{MYDATA|||\$$^p^££"
How can I do to capture MYDATA, using DATAFOUND as a key entry.
In my whole file, after DATAFOUND I have 8 bytes and then the searched values (here it's MYDATA).
Any advice and help are welcome.
PS: I am new programmer and I am not from an English speaking country...So be comprehensive.
|
|
|
|
|
mamamiya_ wrote: Hello everybody
welcome to CodeProject
mamamiya_ wrote: I have a binary file
For File I/O discussions "binary" means the data in the file contains bytes with the value of ZERO. In that case using String library functions are problematic.
mamamiya_ wrote: How can I
You need to parse the file. If, as discussed above, the data is all string data then there are numerous methods such as Regular Expressions. However deciding the best method of parsing and searching the data requires a knowledge of the file format.
|
|
|
|