Solved

Connection String for Teradata in Classic ASP versus .NET

Posted on 2010-11-16
8
1,735 Views
Last Modified: 2013-11-11
Hi Experts,
I'm trying to make this script work when I save the file with .aspx extension.
The first part of the script captures the logged in person's login ID, and the second part matches it with his Emp_Id, First and Last name, then displays this info on the page.
It's working perfectly when I use Classic ASP and save the file with .asp extension.
Can anyone please walk me through the process of converting it to .NET and make it work with .aspx extension?
Thank you
<%
If Request.ServerVariables("LOGON_USER") = "" Then
Response.Status = "401 Access Denied"
Response.End
End If
%>
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=Teradata;DRIVER={Teradata};UID=MyUID;PWD=MyPWD;Persist Security Info=True;"

set rs = Server.CreateObject("ADODB.recordset")

Dim UserID
UserID = Request.ServerVariables("LOGON_USER")
'if always 3 character User ID with '\'
UserID = Mid(UserID, 5)
rs.Open "SELECT First_Name, Last_Name, Emp_Id FROM PhoneBook WHERE Emp_Id = '" & UserID & "'", conn

do until rs.EOF
First_Name = rs("First_Name")
Last_Name = rs("Last_Name")
Emp_Id = rs("Emp_Id")
 rs.MoveNext
loop
rs.close
conn.close
%>

<%=First_Name%> <%=Last_Name%> <%=Emp_Id%>

Open in new window

0
Comment
Question by:baxtalo
  • 5
  • 3
8 Comments
 

Author Comment

by:baxtalo
ID: 34149871
This is the error message I get on line 8 after I used the Web.Config file:
Compiler Error Message: BC30807: 'Let' and 'Set' assignment statements are no longer supported.
I don't know how to  correct it, and what to use instead of Set in my connection string
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34150343
A literal translation to VB.Net would be something like:

        If Request.ServerVariables("LOGON_USER") = "" Then
            Response.Status = "401 Access Denied"
            Response.End()
        End If

        Dim UserID As String = Request.ServerVariables("LOGON_USER")
        'if always 3 character User ID with '\'
        UserID = Mid(UserID, 5)

        Dim conn As Odbc.OdbcConnection = New Odbc.OdbcConnection("DSN=Teradata;DRIVER={Teradata};UID=MyUID;PWD=MyPWD;Persist Security Info=True;")
        Dim cmd As Odbc.OdbcCommand = New Odbc.OdbcCommand("SELECT First_Name, Last_Name, Emp_Id FROM PhoneBook WHERE Emp_Id = '" & UserID & "'", conn)
        conn.Open()

        Dim reader As Odbc.OdbcDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)

        '// assuming you're only expecting one result
        If reader.Read() Then
            First_Name = reader.GetString(reader.GetOrdinal("First_Name"))
            Last_Name = reader.GetString(reader.GetOrdinal("Last_Name"))
            Emp_Id = reader.GetInt32(reader.GetOrdinal(("Emp_Id"))
        End If

Open in new window


Assuming that the TeraData driver is odbc. To display the values you would normally assign them to control properties rather than just dumping them to the browser too.
0
 

Author Comment

by:baxtalo
ID: 34150566
I'm absolutely new at VB.Net
How do I make this into a web page? Where do I need to put the brackets?
If I save it the way it is now the browser displays it as plain text.
Thanks
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:baxtalo
ID: 34150585
I dont' have Visual Studio, I'm just using Notepad to write my code.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34150646
Trying to write and compile an ASP.Net page using notepad is going to be fiddly to say the least. You would be best grabbing yourself a copy of Visual Studio Express, which is free and will make your life a whole lot easier.

Classic ASP is an interpreted language, which is why it is easy to write in Notepad. .Net languages are all compiled, so the process isn't quite as simple.
0
 

Author Closing Comment

by:baxtalo
ID: 34150820
Thank you very much. I thought that it can be done using Notepad. Until now I coded classic ASP only, and I've never used WYSIWYG editors. I always liked writing the code of my pages myself in TextPad.
I guess I will have to learn using Visual Studio. Can you recommend any books, or web sites that could help me learn using .NET very quickly?
I really appreciate your help.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 34153014
The best place to start would be Microsofts own:

    http://www.asp.net
0
 

Author Comment

by:baxtalo
ID: 34153456
Great, thank you!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C#, asp.net MVC, sql server, LINQ 3 32
how to change the view engine in visual studio 2015 enterprises edition 7 45
imap mails 1 22
Hide cell in a table 2 9
Salesforce.com’s Console is a great tool to view activities, leads, contacts, accounts and opportunities all in one screen. It is particularly effective during call blocks and working numerous activities at a time in a quick, repetitive fashion (suc…
Note: You must have administrative privileges in order to configure lead or case queues. Salesforce.com (http://www.Salesforce.com) is a cloud-based customer relationship management (CRM) system. It is widely used around the world by sales and ma…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question