4 Replies - 213 Views - Last Post: 09 July 2014 - 01:47 AM Rate Topic: -----

#1 eg92  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 25-June 14

Oracle in Unix

Posted 01 July 2014 - 04:30 AM

I created an application in vb.net which retrieves all email addresses stored in an Oracle database and sends email to them. In this case, the oracle database is stored on Windows platform.
Is there any way of doing the same thing if the Oracle database is in Unix?
Please help.
My code is as follows-
Imports System.Net.Mail
Imports System.Data.OleDb
Public Class Form1
    Dim email As New MailMessage
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim smtp_server As New SmtpClient
        Dim uid, pwd, str As String
        Dim cn As New OleDbConnection
        Dim cmd As New OleDbCommand
        Dim dr As OleDbDataReader

        cn = New OleDbConnection("Provider=MSDAORA;Persist Security Info=True;User ID=myuid;password=mypwd")
        cn.Open()
        str = "Select email from stud"
        cmd = New OleDbCommand(str, cn)
        dr = cmd.ExecuteReader

        If txtbdy.Text = Nothing Then
            MsgBox("Body can't be left blank!")
            Exit Sub
        End If

        If txtfrm.Text = Nothing Or txtpwd.Text = Nothing Then
            MsgBox("Address or password field can't be left blank!")
            Exit Sub
        End If

        uid = txtfrm.Text
        pwd = txtpwd.Text
        Try
            smtp_server.UseDefaultCredentials = False
            smtp_server.Credentials = New Net.NetworkCredential(uid, pwd)
            smtp_server.Port = 587
            smtp_server.EnableSsl = True
            smtp_server.Host = "smtp.gmail.com"

            email.From = New MailAddress(txtfrm.Text)
            While dr.Read
                email.To.Add(dr(0))
            End While
            email.Subject = txtsub.Text
            email.IsBodyHtml = False
            email.Body = txtbdy.Text
            smtp_server.Send(email)
            MsgBox("Mail sent!")

        Catch ex As Exception
            MsgBox("The mail could not be sent due to one of the following errors:" + vbCrLf + "1.The system is not connected to the Internet" + vbCrLf + "2.The sender's or recipient's address was typed incorrectly." + vbCrLf + "3.Password was typed incorrectly.")
        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Text = "Email Sender"
        txtpwd.UseSystemPasswordChar = True
        Me.BackColor = Color.LightSkyBlue
        txtfrm.BackColor = Color.LightYellow
        txtatt.BackColor = Color.LightYellow
        txtbdy.BackColor = Color.LightYellow
        txtpwd.BackColor = Color.LightYellow
        txtsub.BackColor = Color.LightYellow
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        OpenFileDialog1.Title = "Please select a file"
        OpenFileDialog1.InitialDirectory = "C:\Users\Administrator\Documents"
        OpenFileDialog1.ShowDialog()
        txtatt.Text = OpenFileDialog1.FileName.ToString
        If txtatt.Text = Nothing Then
        Else
            Dim attachment As New Attachment(txtatt.Text)
            email.Attachments.Add(attachment)
        End If
    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        txtatt.Text = Nothing
        txtbdy.Text = Nothing
        txtfrm.Text = Nothing
        txtpwd.Text = Nothing
        txtsub.Text = Nothing
        email.Attachments.Clear()
    End Sub
End Class


Please tell me what changes should I make if the Oracle database is stored in Unix.

Is This A Good Question/Topic? 0
  • +

Replies To: Oracle in Unix

#2 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5820
  • View blog
  • Posts: 12,672
  • Joined: 16-October 07

Re: Oracle in Unix

Posted 01 July 2014 - 05:16 AM

The Oracle RDBMS is a database server. The hosting OS of that server is irrelevant to the client.

The code you have there runs on a client. Just point your connection string to a different box and go from there.

It's odd that you don't have a "Data Source" field in the connection string. I guess it would default to localhost, which is probably your confusion. Always fill that in.

More here: https://www.connecti...le-db-oraoledb/
Was This Post Helpful? 1
  • +
  • -

#3 eg92  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 25-June 14

Re: Oracle in Unix

Posted 02 July 2014 - 12:51 AM

Thanks baavgai, but then how do i modify my connection string to connect to the database on the server?
I visited the link you mentioned, but then again how do I mention in the connection string that my database is on another system?
Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5820
  • View blog
  • Posts: 12,672
  • Joined: 16-October 07

Re: Oracle in Unix

Posted 02 July 2014 - 04:26 AM

Oracle has a number of ways to find a database on a network. The most common, and probably most self contained and easiest, is the tnsnames.ora file.

Depending on how much oracle client you have installed, there are Oracle GUI tools that will help you set this up.

The Oracle database server runs a service called the listener. Ultimately, an oracle database is identified by the host server name, the listener port, and the database SID or service name.

You take the connection information and make an "alias" for it in that tnsnames.ora file. You can partially verify this, and also check the location of that file, by calling "tnsping aliasName" from the command line.

That alias is the "Data Source" value in the connection string.

Before you can get that VB code working, you'll actually want to validate connection strictly via oracle tools. Mostly tnsping and then sqlplus to the database. If the oracle client is set up, then the .NET stuff should follow.

I found this, which looks reasonably complete: https://kb.iu.edu/d/aznp

I normally don't throw folks at Google, but Oracle configurations can be big, messy, complex affairs designed to address any number of architectures. The shear user unfriendliness makes "Oracle DBA" an actual job. Many have done a much better job documenting this stuff than I could ever hope to.

Good luck.
Was This Post Helpful? 0
  • +
  • -

#5 eg92  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 25-June 14

Re: Oracle in Unix

Posted 09 July 2014 - 01:47 AM

Thanks a lot baavgai! It helped a lot! my problem is solved now :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1