|
hello guys... I am trying to write this simple service using this tutorial.
<a href="http://msdn.microsoft.com/en-us/library/aa984464(v=vs.71).aspx">MSDN Tutorial</a>.
To the best of my knowledge, i am doing exactly the same as the tutorial suggests. But still it does not insert the record in the SQL SERVER. The problem is, it does not give an error as well, thats why dont know what to do.
I have tested this insertion operation with another simple Windows Forms application and it works absolutely fine.
What can be the problem? thnx for any pointers.
|
|
|
|
|
We would have to see your code.
|
|
|
|
|
Here you are...
<pre lang="c#">
protected override void OnStart(string[] args)
{
InsertRec();
}
protected override void OnStop()
{
UpdateRec();
}
private void InsertRec()
{
string name = "abc";
string address = "abc";
string className = "abc";
string phone = "123456";
SqlConnection connection = new SqlConnection("Data Source=MUZE-PC\\SQLEXPRESS; Initial Catalog=StudentDB; Integrated Security=SSPI");
SqlCommand command = new SqlCommand("InsertStudent", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@Name", SqlDbType.NVarChar).Value = name;
command.Parameters.Add("@Address", SqlDbType.NVarChar).Value = address;
command.Parameters.Add("@Class", SqlDbType.NVarChar).Value = className;
command.Parameters.Add("@Phone", SqlDbType.NVarChar).Value = phone;
try
{
connection.Open();
int res = command.ExecuteNonQuery();
}
catch (Exception ex)
{ connection.Close();}
finally
{ connection.Close(); }
}
private void UpdateAttendence()
{
int ID = 1;
string machineName = "Ali";
SqlConnection connection = new SqlConnection("Data Source=MUZE-PC\\SQLEXPRESS; Initial Catalog=StudentDB; Integrated Security=SSPI");
SqlCommand command = new SqlCommand("UpdateStudent", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@StudentID", SqlDbType.Int).Value = ID;;
command.Parameters.Add("@Name ", SqlDbType.NVarChar).Value = name;
try
{
connection.Open();
int res = command.ExecuteNonQuery();
}
catch (Exception ex)
{ connection.Close(); }
finally
{ connection.Close(); }
}
</pre>
|
|
|
|
|
It doesn't work because you're using a connection string that uses the current credentials to login to SQL Server. That only works IF:
1) Windows Authentication is turned on in SQL Server.
2) The code is running under an account that the SQL Server trusts.
Your problem is your service is running under LocalSystem by default, which SQL Server does NOT trust.
There are 2 solutions to this. The first is to create a user in SQL Server and assign it's permissions properly to access the database in questions, then modify the connection string in your code to use the account and NOT use Integrated Security.
The second is to change the account that your service is running under, to something like YOUR account. Start->Run->Services.msc. Find your service, then right-click on it and click Properties. Click the LogOn tab and it should be pretty obvious from there.
In the future, you might want to learn WHY those things are listed in the connection string and figure out what each option does.
|
|
|
|
|
hai everyone ,
My problem is i have a employee code like EMPLOYEE
i would like to change this to EMPLOYEE000001,EMPLOYEE000002 this format.
How can i do this? with c# please help me
Arunkumar
Arunkumar
|
|
|
|
|
You can use the Format[^] method like:
uint EmployeeNumber = 1;
String.Format( "EMPLOYEE{8:D}", EmployeeNumber );
Remember you will be limited to 999999 employees.
0100000101101110011001000111001011101001
|
|
|
|
|
It is
string.Format("EMPLOYEE{0:D6}",EmployeeNumber);
|
|
|
|
|
Where is the employee code stored? How do you determine which EMPLOYEE should be EMPLOYEE00001 and which EMPLOYEE00075?
We need more information before we can give you a meaningful answer.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
André Kraak,ProEnggSoft
Thank you for your answer and it's works!
OriginalGriff, the employee code is stored in the database and it just a field for naming(like a roll no) a employee. i have a id filed for managing employees.
when admin add a employee program fetch last inserted employee code. i writed a program for increasing the count.
Thanks,
Arunkumar.t
|
|
|
|
|
Arunkumar.Koloth wrote: OriginalGriff, the employee code is stored in the database and it just a field for naming(like a roll no) a employee. i have a id filed for managing employees.
when admin add a employee program fetch last inserted employee code. i writed a program for increasing the count.
If you're using SQL Server why are you not using the identity column instead?
http://msdn.microsoft.com/en-us/library/aa933196(v=sql.80).aspx[^]
If you're not using SQL server there's probably some similar function in your database.
|
|
|
|
|
Marcus_2,
My project is in MySQL server so i thing it is required.. suggest me if you have any other great idea.
Thank you
Arunkumar
|
|
|
|
|
Hi
I've no idea about MyQL, but perhaps this might be helpful or at lest something to read and remember the functionality for future use:
http://bytes.com/topic/mysql/answers/652076-how-create-identity-column-mysql
It depends on how you do it, I just read this
Arunkumar.Koloth wrote: i writed a program for increasing the count.
and tried to give an idea about using a feature built into a lot of databases.
|
|
|
|
|
Thanks For the link Marcus_2
|
|
|
|
|
OK so i will try again to explain
the full url or request is http://www.yonewmail.com?hellocarl but the ?hellocarl part is diffrent each time i need to be able to set this field with a text box entry
webBrowser1.Navigate(http://www.yonewmail.com,+ textbox1.text"_self", null, "Mozilla/5.0 (");
can someone help me please
|
|
|
|
|
Have you tried
webBrowser1.Navigate("http://www.yonewmail.com" + "?" + textbox1.text);
|
|
|
|
|
webBrowser1.Navigate("http://www.coolmail.com/en/?", "_self", null, "Mozilla/5.0 " + textBox1.Text);
<pre lang="c#">textBox1.Text="hello : example code
upon checking with a http debuger it send this string to web
http:
it does not send the textbox text at all
the string should look like this
http:
|
|
|
|
|
You would be better to use a StringBuilder[^] in such a case, as it allows much greater flexibility than a simple String . It is also not good form to use concatenation in cases like this as it can lead to injection issues where your code can be hacked by malicious users.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
|
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
webBrowser1.Navigate(http://www.yonewmail.com?"+ textbox1.text+"_self", null, "Mozilla/5.0");
Chona1171
Web Developer (C#), Silverlight
|
|
|
|
|
Hi all!
I asked for the issue as follows:
I can program in C
Windows Form. I have two Form: Form1 and Form2.
Form1 has a datagrid and a button1. In the DataGrid displays the user with 2 column username and password.
Form2 has two TextBox is txtTenDangNhap and txtMatKhau, and a Button btnLuu.
In Form1:
When Form1 loads the program will load a list of accounts available in the database to the DataGrid.
When you click Button1, then Form2 will appear in the form of ShowDialog. (Form2 f2 = new Form2 (); f2. ShowDialog ()) (Note: Form1 is still not closed)
On Form2: When pressing Button btnLuu, the new account will be saved to the database and Form2 will close.
When Form2 is closed on Form1 DataGrid will load the data with the new account added.
For help yourself with!
|
|
|
|
|
Do you have a specific question you need help with?
/ravi
|
|
|
|
|
I have done, but also want to address up on this issue and for all, who needs it to use:
In Form1:
Set the button code below in the form1
Form2 f = new Form2();
if (f.ShowDialog() == DialogResult.OK)
{
}
else
{
}
In form2:
Set the button code below in the form 2
this.DialogResult = DialogResult.Cancel;
|
|
|
|
|
If a dialog wants the caller Form to perform some action, then it normally sets DialogResult to one of the predefined values (but not None nor Cancel), and the caller tests for that value.
Using Cancel and putting the action in the else part of the test is extremely weird. Were you sober when you wrote this?
|
|
|
|
|
The "proper" way to do this is to provide two buttons in Form2, and set their properties appropriately.
The "OK" button has the DialogResult set to Dialogresult.OK
The "Cancel" button has the DialogResult set to Dialogresult.Cancel
The Form has its AcceptButton property set to the OK button, and is CancelButton set to the Cancel Button.
The framework will then handle the buttons without any event handlers being necessary.
These properties can be set at design time.
In fact, I use a OK/Cancel button so often, I have made a VS Template to create it automatically - there is a Tip here which describes how to do it: Create Visual Studio forms for items you frequently use[^]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|