Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Prob Connection of server in ASP.NET using VB.NET

Author  Topic 

eddom
Starting Member

5 Posts

Posted - 2005-10-20 : 14:48:14
Need help here, i had develop a simple system by using asp.net, but i need to connect to the sql server by using vb.net in the asp.net. I had try to create a sqlconnection object in the web form, and it work well in the microsoft studio.net with the connection string: "workstation id=EDDOM;packet size=4096;user id=sa;data source="EDDOM\TARC";persist security info=False;initial catalog=TARCDB". i am able to view and connect to the sql server in the microsoft studio.net but when i try to access the login.aspx file by using the internet explorer, this problem occur:

[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

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.Runtime.InteropServices.COMException: [DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.

is any body know why? i had try to use the same connection string in asp and it work. but just why that connection string cant work with vb.net? i will be appreciate if anyone can provide me an example so that i can study on it. thanks.

eddom
Starting Member

5 Posts

Posted - 2005-10-21 : 10:53:36
Can anyone help me out?
Go to Top of Page

iktheone
Yak Posting Veteran

66 Posts

Posted - 2005-10-21 : 10:56:55
did u create the connection by typing it or did u use the Data Connection Wizard?
Go to Top of Page

eddom
Starting Member

5 Posts

Posted - 2005-10-21 : 12:40:35
I tried both ways, but it doesn't work also.
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-10-21 : 13:40:58
All right, we need some more details, because your question sounds like you believe ASP.NET and VB.NET to be different when in actuality, VB.NET is one of the languages you can use to create an ASP.NET application. SO, when you say you can't get it to work in VB.NET, are you talking about creating a desktop application as opposed to a web application? Or are you referring to the difference between making a connection from the Visual Studio.NET IDE vs. connecting from your page when running in DEBUG mode or running the page on an actual server?

When you say that connection string in ASP works, what does this mean? Classic ASP 3.0 instead of .NET? ASP.NET locally?

---------------------------
EmeraldCityDomains.com
Go to Top of Page

eddom
Starting Member

5 Posts

Posted - 2005-10-21 : 14:39:19
Actually i am developing a ASP.NET project and i include some code of VB.NET (For eg i use the VB.Net code in a Login button to connect to the SQL server). I had include the connection string in the public sub login_Click and i also does import the system.data.sqlclient. And the problem i met was after i press the Login button in the internet explorer, it shown me that the server cant be found. Thus, i tot there is some error with my connection string, then i tried the same connection string in the ASP(not asp.net), and i can actually connect to the database succesfully with the ASP. Thus, i am think of is that i got to set anything in my pc? What make me think weird is that after this problem occur, i tried to create a new project, and i ever cant run a simple .aspx page in the internet explorer, and it shown me:

Server Error in '/' Application.
--------------------------------------------------------------------------------

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested Url: /web1/webform1.aspx
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573

every new project's .aspx file cant been execute. What actually happened?
Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2005-10-21 : 15:00:20
The next steps would be to

1) Set a stop-point in your debugger and verify that it actually IS using the connection string you think it is (i.e. is it being properly assigned/retrieved)
2) Post your code for login_Click so we can review it.

---------------------------
EmeraldCityDomains.com
Go to Top of Page

eddom
Starting Member

5 Posts

Posted - 2005-10-21 : 15:07:29
Below is the code for Login_Click

Private Sub InitializeComponent()
Me.SqlConnection1 = New System.Data.SqlClient.SqlConnection
Me.SqlCommand1 = New System.Data.SqlClient.SqlCommand
Me.SqlConnection1.ConnectionString = "workstation id=""EDDOM"";packet size=4096;integrated security=SSPI;data source=EDDOM\TARC;persist security info=False;initial catalog=lib"
Me.SqlCommand1.CommandText = "SELECT MemberID, Passwd FROM Member WHERE (MemberID = @MemberID) AND (Passwd = @Password)"
Me.SqlCommand1.Connection = Me.SqlConnection1
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@MemberID", System.Data.SqlDbType.VarChar, 7, "MemberID"))
Me.SqlCommand1.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Password",System.Data.SqlDbType.VarChar, 10, "Passwd"))
End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
InitializeComponent()
End Sub

Private Sub Login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click

Dim Member As String
Dim Passwd As String

Member = MemberID.Text
Passwd = Password.Text

SqlCommand1.Parameters("@MemberID").Value = Member
SqlCommand1.Parameters("@Password").Value = Passwd

SqlConnection1.Open()
Dim dreader As SqlClient.SqlDataReader
dreader = SqlCommand1.ExecuteReader(CommandBehavior.SingleRow)

If dreader.Read() Then
Server.Transfer("StudentAction.aspx")
Else
Label.Text = "Invalid Member ID or Password!!"
End If

dreader.Close()
SqlConnection1.Close()

End Sub
Go to Top of Page
   

- Advertisement -