| | |
Prblem with sql sever connection
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2005
Posts: 19
Reputation:
Solved Threads: 0
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
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
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
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
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....
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....
•
•
Join Date: Jun 2005
Posts: 19
Reputation:
Solved Threads: 0
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
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
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.
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.
![]() |
Similar Threads
- SQL not a trusted connection?! (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Pseudo web page names
- Next Thread: i need your experience please help me
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formview gridview gudi iis javascript list listbox login menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl






:cheesy: