944,081 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 7654
  • ASP.NET RSS
Jun 14th, 2005
0

Prblem with sql sever connection

Expand Post »
hi every one .. thank you for entering this message

i have a problem with connection to sql server 2000 from vb.net
the message is :
The ConnectionString property has not been initialized.


and this is my code

Line 41: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Line 42: cmd.CommandText = ("insert into reg values ('" & lb1.Text.Trim & "','" & lb2.Text.Trim & "',)")
Line 43: cnn.Open()..............................(red ERROR)
Line 44: cmd.ExecuteNonQuery()
Line 45: cnn.close()


please i need your experience to solve my problem
thank you again
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fineline is offline Offline
19 posts
since Jun 2005
Jun 14th, 2005
0

Re: Prblem with sql sever connection

Since I dont see you code I assume the following will solve you problem..

you gotta initiliase the connection string....
Once you declare it..
1.dim myconnection as sqlconnection
2.myconnection= New SqlConnection("server = localhost;database=databas;Trusted_Connection=Yes")

Since I dont see your entire code ,I assume you havent included the connection object inside the sqlcommand..For the command use something like this..

dim cmd as sqlcommand
dim strcmd as string = "insert into reg values ('" & lb1.Text.Trim & "','" & lb2.Text.Trim & "'
cmd = New SqlCommand(strcmd, myconnection)


Hope it helps
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jun 14th, 2005
0

Re: Prblem with sql sever connection

Thank you for your intersting and its solve my problem but unforchenatly i have ERROR and this is th message :
Login failed for user 'admin'. Reason: Not associated with a trusted SQL Server connection.



i need your help thank you for intersting

thank you again
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fineline is offline Offline
19 posts
since Jun 2005
Jun 14th, 2005
0

Re: Prblem with sql sever connection

iam sorry the message now is :

Login failed for user 'SHADID\ASPNET'.


shadid is my name of computer and iam using IIS

what can i do
please reply to me i need your experiance

thank you again
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fineline is offline Offline
19 posts
since Jun 2005
Jun 14th, 2005
0

Re: Prblem with sql sever connection

ohh.....Whats your Authentication ...is it Windows ? or SQL server ?It has to be any one of the following ??
1.Did you register your computer in SQL server.
To do that goto enterprise manager and right click your server group and select the option NEW SQL SERVER REGISTRATION and add your local computer to sql server..

2.If you have done that and then its still not working .... Then your connection mode is faulty..Goto Enterprise manager and select your local computer and right click and hit properties..Select the Security tab and then select your authentication mode..
I prefer you to select both and windows and Sql server mode..

If it still doesnt work copy and paste your code....
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jun 14th, 2005
0

Re: Prblem with sql sever connection

thank you for intersting to my problem but the problem still i dont know what can i do
this is the ERROR message :-
Login failed for user 'SHADID\ASPNET'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'SHADID\ASPNET'.

Source Error:


Line 50:
Line 51: 'cmd.CommandText = ("insert into reg values ('" & lb1.Text.Trim & "','" & lb2.Text.Trim & "')" & "con")
Line 52: myconnection.Open()
Line 53: cmd.ExecuteNonQuery()
Line 54: myconnection.Close()

and this is the code:


Imports System.configuration
Imports System.Data.SqlClient



Public Class WebForm1
Inherits System.Web.UI.Page
Dim myconnection As SqlConnection
Dim cmd As SqlCommand


'Dim cnn As New SqlConnection(ConfigurationSettings.AppSettings("workstation"))
'Dim cmd As New SqlCommand
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
myconnection = New SqlConnection("server = shadid;database=sh;Trusted_Connection=Yes")


'cmd.Connection = myconnection
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'cnn = New SqlConnection("Driver={SQL Server};User ID=Admin;Database=sh")

Dim strcmd As String = "insert into reg values ('" & lb1.Text.Trim & "','" & lb2.Text.Trim & "' "
cmd = New SqlCommand(strcmd, myconnection)

'cmd.CommandText = ("insert into reg values ('" & lb1.Text.Trim & "','" & lb2.Text.Trim & "')" & "con")
myconnection.Open()
cmd.ExecuteNonQuery()
myconnection.Close()


Response.Redirect("WebForm2.aspx")


End Sub
End Class


and i write in web config. this statement :


<appSettings>
<add key="workstation" value="data source=shadid;
User ID=admin;initial catalog=sh;persist security info=False;packet size=4096"/>
</appSettings>

please advice me iam thanking you very much for your intersting
thank you again
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fineline is offline Offline
19 posts
since Jun 2005
Jun 15th, 2005
0

Re: Prblem with sql sever connection

This should do it ...
1. open enterprise manager. (The enterprise manager will be available within the sqlserver program group in windows. Start->Programs->Microsoft SQL Server->enterprise manager)

2. In the ( database window ( left pane ) locate your database and expand. You will see tables, view, users etc listed below. Dblclick the users icon. On the right pane dblclick the machiname\ASPNET user you had created earlier. This will open up the "database user properties" window. You will see that the database role "public" is already selected.

3. Now additionally select the db_datareader role as well. Click apply.

This will give the database read permission to the ASPNET user and hopefully fix your problem.
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jun 15th, 2005
0

Re: Prblem with sql sever connection

remember to close the parenthesis in insert string(strcmd)
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005
Jun 15th, 2005
0

Re: Prblem with sql sever connection

Quote originally posted by Letscode ...
remember to close the parenthesis in insert string(strcmd)

Thank you very much really now iam happy i cant beleive that the program is run now .. :cheesy:
thank you again


i'd like to be a good freinds

thank you again iam too happy
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fineline is offline Offline
19 posts
since Jun 2005
Jun 15th, 2005
0

Re: Prblem with sql sever connection

No Problem...
Glad I could help
Reputation Points: 11
Solved Threads: 6
Junior Poster
Letscode is offline Offline
175 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Pseudo web page names
Next Thread in ASP.NET Forum Timeline: i need your experience please help me





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC