2 Replies - 1850 Views - Last Post: 15 December 2008 - 03:06 AM Rate Topic: -----

#1 raghavendra   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 11-August 08

Problem with asp.net and sql server 2005

Post icon  Posted 13 December 2008 - 03:54 AM

HI all,

I am preparing a website for our company and the problems that i am facing are listed below:

Actually i have to insert the data that has been entered into the form into a database. --this is my requirement.

1. Problem with sql server connection string and my connection string is written below:
myConnection = New SqlConnection("server=.\sqlexpress;uid=CONFAI17\Administrator;pwd=;database=HRDATA")


The error message that i am getting is "Login failure for the user".

2 If i remove the user name and password in the connection string(in the code for buttion_click) and i am using another connection string then the problem is at
myCommand.ExecuteNonQuery()

The error message is "ExecuteNonQuery() is not initialized".

I am placing the code tht i have written for button_click below could anyone please help me out by looking at the code and suggest me what to do then it is of a great help for me.

Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "data source=.\SQLEXPRESS;initial catalog=HRDATA;integrated security=sspi;"
 Dim myCommand As New System.Data.SqlClient.SqlCommand
        myCommand.CommandText = "insert into Employee Data values('" & txt_name.Text & "')"
con.Open()
myCommand.ExecuteNonQuery()
con.Close()
End Sub



Any link for a tutorial or any suggestions are appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with asp.net and sql server 2005

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Problem with asp.net and sql server 2005

Posted 13 December 2008 - 10:56 AM

Your first error is easy to solve, the username/password combination you provide in your connection string are incorrect for that user. Also check out ConnectionStrings.Com for a properly formatted connection string.

Now for you second error, you never set the Connection Property of your SqlCommand instance so it doesnt know which connection to use. Take a look at the changes I've made to your code and see if it works for you

Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "data source=.\SQLEXPRESS;initial catalog=HRDATA;integrated security=sspi;"
Dim myCommand As New System.Data.SqlClient.SqlCommand
myCommand.CommandText = "insert into Employee Data values('" & txt_name.Text & "')"
myCommand.Connection = con
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
con.Close()
End Sub




For future reference your inline SQL query is ripe for a Sql Injection attack, try using parametrized queries or stored procedures for security xsakes.
Was This Post Helpful? 0
  • +
  • -

#3 raghavendra   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 11-August 08

Re: Problem with asp.net and sql server 2005

Posted 15 December 2008 - 03:06 AM

Hi,

Thanks for ur reply and i still getting the same error at
myCommand.ExecuteNonQuery() 

The error says tht ExecuteNonQuery is not initialized

Also i have another problem with calender control, according my requirement whenever the user places the cursor in the textbox then the calender should be visible and the code for tht i have written is

 If (txt_dob.Text) Then
			Calender2.Enabled = True
			txt_dob.Text = Calender2.SelectedDate.DayOfWeek



The problem is with null pointer reference



looking forward for ur reply......


thanks in advance.........
Raghu.....








View PostPsychoCoder, on 13 Dec, 2008 - 09:56 AM, said:

Your first error is easy to solve, the username/password combination you provide in your connection string are incorrect for that user. Also check out ConnectionStrings.Com for a properly formatted connection string.

Now for you second error, you never set the Connection Property of your SqlCommand instance so it doesnt know which connection to use. Take a look at the changes I've made to your code and see if it works for you

Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "data source=.\SQLEXPRESS;initial catalog=HRDATA;integrated security=sspi;"
Dim myCommand As New System.Data.SqlClient.SqlCommand
myCommand.CommandText = "insert into Employee Data values('" & txt_name.Text & "')"
myCommand.Connection = con
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
con.Close()
End Sub




For future reference your inline SQL query is ripe for a Sql Injection attack, try using parametrized queries or stored procedures for security xsakes.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1