|
include below namespace in your projcet:
using System.Data.SqlClient;
|
|
|
|
|
|
Have a read of this using ADO.NET[^]
there are some simple tutorials in the article
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
If the data you want to save is in a grid which is data-bound to a database table or view, or you're using EF or similar. you can just ask it to persist itself. Otherwise, you're going to have to construct a SQL query to store the data that you want. SQL Server 2005 doesn't have an equivalent of 'insert ... on duplicate key update' so doing a single query can be impossible.
Make sure you use a parameterised query, and handle failures to write gracefully.
|
|
|
|
|
hi,
i am using visual studio 2008
and making project in c#.
i had created web application form
but i am not able to connect it with database.
em using sqlserver2005 as database
shubhi
|
|
|
|
|
If you are having a problem with connections, this[^] would be your best bet.
|
|
|
|
|
What do you mean by "not able to connect it with database"?? What does you code look like that does the connection and query work?? What are the error messages you're getting?? Just saying "it doesn't work" doesn't help you.
|
|
|
|
|
i am not able o make connection con
|
|
|
|
|
shubham salwan wrote:
i am not able o make connection con
You do realize that we cannot see your code, or have your project available, or read your mind. If you expect to get help for your problems, you have to show the code that you are having trouble with and share the errors you are getting. We cannot possibly help you resolve issues if you do not give us the information that is needed to help you! Do you call your mechanic and tell him that your car is "broke" and expect that they should know eactly what you mean the problem is?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
string connString = "Data Source=shubhi-PC;Initial Catalog=employee;uid=sa;pass=abc;Integrated Security=True"; SqlConnection conn = new SqlConnection(connString);
conn.Open();
String sql = "INSERT INTO emp_detail(empid,empname,empadd,empsal) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
cmd.ExecuteNonQuery();
conn.Close();
textBox1.Text="";
i want to save data to sqlserver2005 ... bt itz not working
|
|
|
|
|
shubham salwan wrote: bt itz not working
Of course it's not working. Your connection string has a user name a password and you are telling it to use integrated security. Not to mention that you did not bother even defining a command object. You do realize that this won't even compile don't you?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Shhhhhhhh.... Don't tell him his code is subject to SQL Injection attacks either
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I figure he has enough trouble without throwing gasoline on the bonfire.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Don't make your SQL statements that way -- use a parameterized query.
|
|
|
|
|
When you use "Integrated Security=True " in your connection string, the user and password given there are ignored - the current Windows user is used for login to the database instead.
|
|
|
|
|
i have to give my connection string to the other so they can connect to my database.
i understand that this is not secure. so i'm working on a new application that encrypt my connection string, give it to the other, and decrypt it before connecting to my database.
of course i didn't show the result of decryption.
i need a suggestion, what encryption is best for this problem?
thank you,
Ahri
|
|
|
|
|
Midnight Ahri wrote: i need a suggestion, what encryption is best for this problem?
The problem with encryption is that you have to provide a mechanic for your app to decrypt it. That means that there's a key to the vault, hanging next to the vault.
If the database is running on their system, and is filled with their data, who would be the legal owner of the database?
Your best option for security would be to provide only access to some webservices, and not have the client interact with the database directly.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
thank you for the reply,
let me explain my application in easier example,
i'm working on address book application, i save telephone, name, address in my own database,
i give this application to my friend, and he can save the data in his own database,
my application can connect to his database (using his connection string & wifi) and i can access his address book, also save it to my database.
Eddy Vluggen wrote: and not have the client interact with the database directly.
usually i was given a corporate project (all client connects to server)
but this time, i don't even understand why i'm given a project like this.
and the worst one, user should be able to read the encryption.
i've try googling, i found some encryption thats impossible to read.
|
|
|
|
|
Midnight Ahri wrote: i give this application to my friend, and he can save the data in his own database,
my application can connect to his database (using his connection string & wifi) and i can access his address book, also save it to my database.
Aah, I misunderstood; you want to prevent users (like you) from reading other users' database (like your friends), correct?
The database usually has a password, passed in the connectionstring. If the user could set his own password, you'd be out of trouble. Ask for the password on startup, and offer an option to "keep logged in", just like a webpage - that should do the trick.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
thank you very much !
|
|
|
|
|
Public key encryption solves the 'key in the vault' problem. Any situation where a key can't be exchanged securely offline first (which is most internet apps) means that you need a public key encrypted key exchange process to create an encrypted channel.
|
|
|
|
|
" we ask the browser to send all the traffic to localhost and then the traffic can be sent to our server
otherwise browser will make requests directly towards the destination server(e.g. google ).."
Transparent proxy can be used in any place it does not break the http and https traffic.
Browser -> lcoal host(create ssl) -> our server -> google
so, how to use use transparent proxy(local host) in middle of browser and destination server??
|
|
|
|
|
What does this have to do with C#?
There are some manuals on the internet on how to set up a proxy. I'd recommend Squid[^], depending on your needs.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I'm trying to use a CookieAwareWebClient (or just a httpwebrequest) to log in to a gargoyle router.
To do so I have to post a password to a utility/get_password_cookie.sh. I can replicate this with code.
NameValueCollection loginData = new NameValueCollection();
loginData.Add("password", "loginpassword");
byte[] returnData = webclient.uploaddata("http://server/utility/get_password_cookie.sh",loginData );
tempData = webclient.Encoding.GetString(data);
tempData = tempData.Replace("\n",string.Empty);
webclient.Headers.Add(tempData);
webclient.DownloadFile("http://server/bandwidth.csv", downloadedFile);
Looking at the local variables of the webclient, the cookiecontainer doesn't contain the "hash" cookie I'm expecting to see.
However if I decode the returnData bytearray (to tempData)I see the text
"Set-Cookie:hash=hashvaluehere; path=/Set-Cookie:exp=1342083624; path=/"
So with that text string I tried adding it as a header to a subsequent webclient request to an internal page within the router.
But no matter what I do it doesn't seem to have any effect.
Why is it not in the CookieCollection? How can I use this hash cookie for a subsequent request?
Following is the CookieAwareWebClient.cs
public class CookieAwareWebClient : WebClient
{
public CookieContainer CookieContainer { get; set; }
public Uri Uri { get; set; }
private string lastRequest;
public CookieAwareWebClient()
: this(new CookieContainer())
{
}
public CookieAwareWebClient(CookieContainer cookies)
{
this.CookieContainer = cookies;
}
protected override WebRequest GetWebRequest(Uri address)
{
WebRequest request = base.GetWebRequest(address);
if (request is HttpWebRequest)
{
try
{
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message);
}
(request as HttpWebRequest).CookieContainer = this.CookieContainer;
if (!String.IsNullOrEmpty(lastRequest))
{
(request as HttpWebRequest).Referer = lastRequest;
}
if (request.Method == "POST" && String.IsNullOrEmpty(request.ContentType))
{
request.ContentType = "application/x-www-form-urlencoded";
}
}
lastRequest = address.ToString();
HttpWebRequest httpRequest = (HttpWebRequest)request;
httpRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
return httpRequest;
}
protected override WebResponse GetWebResponse(WebRequest request)
{
HttpWebResponse response = (HttpWebResponse)base.GetWebResponse(request);
String setCookieHeader = response.Headers[HttpResponseHeader.SetCookie];
this.CookieContainer.Add(response.Cookies);
if (setCookieHeader != null)
{
if (setCookieHeader != null)
{
Cookie cookie = new Cookie();
this.CookieContainer.Add(cookie);
}
}
return response;
}
}/pre>
|
|
|
|
|
HTTP responses use Set-Cookie, as an instruction to the client. If you want to include a cookie in a request, use Cookie: instead.
|
|
|
|