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

11 Years
Discussion Span
Last Post by Letscode

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


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 :)


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


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....


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 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")


End Sub
End Class

and i write in web config. this statement :

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

please advice me iam thanking you very much for your intersting
thank you again

Edited by happygeek: fixed formatting


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.


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 .. :D :cheesy:
thank you again

i'd like to be a good freinds

thank you again iam too happy

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.