Friday, February 24, 2012

Creating a Connection

I am trying to connect to a database on an MS Sql server, I typed the code exactly like what is shown in the tutorial and I keep getting an error... (Error in line 6)

Line 4: Dim oODBCConnection As OdbcConnection
Line 5: Dim sConnString As String = _
Line 6: "Driver={SQL Server};" &_
Line 7: "Server=209.151.130.8;" &_
Line 8: "Database=blah;" &_
...(Error in line 6)

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30203: Identifier expected.First off - I'd say you're going in the wrong direction, since it looks as if you're trying to connect with a SQL server - -
ASP.Net has a namespace that talks directly to SQL Server...
it should look more like the info in :
Database Connect and Display Samples

Which tutorial are you reading?|||I've been using Classic ASP untill now, I'm moving on up to .NET...

I'm looking for a very simple way to retreave some data from a database and display it using of of the data web controls..

The part that I'm having trouble with is comunicating with the server (creating a connection)..

On The Side:
I've read about placing the connection string in the AppSettings section in web.config, but this isn't going to work in my case because I am only working with a single aspx file... Am I correct in saying that this way won't work because I'm using only one aspx file..|||Ps: I changed the ip, and user name for security reasons...

<% @.Import Namespace="System.Data.SqlClient" %>
<% @.Import Namespace="System.Data" %>
<script language="vb" runat="server" debug="true"
Sub Page_Load(Source as Object, E as EventArgs)
Dim strConn as string = "server=555.555.11.11;uid=test;pwd=test1;database=webland"
Dim MySQL as string = "Select pl_username From Users"
Dim MyConn as New SQLConnection(strConn)
Dim ds as DataSet=New DataSet()
Dim Cmd as New SQLDataAdapter(MySQL,MyConn)
Cmd.Fill(ds,"Customers")
myDataList.Datasource=ds.Tables("users").DefaultView
myDataList.DataBind()
End Sub

</script
<asp:DataList runat="server" id="myDataList"
Width="85%" Border="1"
HorizontalAlign="Center"
Font-Name="Verdana" CellPadding="4"
Font-Size="10pt"
RepeatColumns="5" >
<ItemTemplate>
Question:<br />
<%# DataBinder.Eval(Container.DataItem, "pl_username") %>
</ItemTemplate>
</asp:DataList
ERROR:
Cannot open database requested in login 'webland'. Login fails. Login failed for user 'test'.
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: Cannot open database requested in login 'webland'. Login fails. Login failed for user 'test'.

BUT:
I bleave that my user name information that I provided is correct..I think taht something else is causing the error, but i'm not getting the correct error message?|||It is very possible that wherever this database resides, that they are not using the standard sql port 1433. A lot of places are doing this now for security by obscurity reasons. Anyway, if you don't know for sure, I would contact the people who host your website and make sure that you have the right port. If it is a different port just add a comma and the port number after the server address. For example if you find out that the port number is 1435, then instead of this:

Dim strConn as string="server=555.555.11.11;uid=test;pwd=test1;database=webland"

try this:

Dim strConn as string="server=555.555.11.11,1435;uid=test;pwd=test1;database=webland"

No comments:

Post a Comment