Page 3 of 3 First 123
  • Jump to page:
    #31
  1. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    Originally Posted by yakirllc
    Another question, please take a look at my code and tell me if I'm doing something worng:
    Code:
    my $conn = Win32::OLE->new('ADODB.connection');
    $conn->open("Provider=SQLOLEDB.1;Password=$passwd;Persist Security Info=True;User ID=$user;Initial Catalog=$target;Data Source=$ip") || do {$connerr = 1};
    ...
    Thanks.
    Instead of just setting a variable on error, why not also log what the error is, something like this:
    Code:
    $conn->open("Provider=SQLOLEDB.1;Password=$passwd;Persist Security Info=True;User ID=$user;Initial Catalog=$target;Data Source=$ip") 
        || do {
            $connerr = 1;
            warn 'Last error was' .  Win32::OLE->LastError() . "\n";
        };
    That way, you can tell exactly what went wrong with your connection.

    And to answer your other question, the connection string stays the same whether to connect to a 32 bit instance or 64 bit instance of MSSQL.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  2. #32
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    25
    Rep Power
    0

    Thanks


    Hi,

    Thanks for the reply.
    I already tried that but all I get is the error code (1) of the failing connection. Doesn't help me much. I asked that because I wanted to know if my syntax of connecting to the MSSQL DB is incorrect but it seems like my syntax is right.

    I have another question, is there a way to set some environment variavbles in the running script and make it to use it.
    I need my script to set some new environment variables and then start running using the new environment variables.

    I know it has nothing to do with MSSQL or DB but it's another question I have and I'd like to have your help.

    Thanks alot again.
  4. #33
  5. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    Originally Posted by yakirllc
    Hi,

    Thanks for the reply.
    I already tried that but all I get is the error code (1) of the failing connection. Doesn't help me much. I asked that because I wanted to know if my syntax of connecting to the MSSQL DB is incorrect but it seems like my syntax is right.
    You are not doing it right then. Read the documentation for the function Win32::OLE->LastError() carefully. If you'd read it, you'll note that it is a special function in that if you read it in numeric context (e.g. $x = Win32::OLE->LastError()), then it will return an error code e.g. 1, 2 etc. However, if you read it in string context, it will return a verbose error message. Therefore, when you print it like this:
    Code:
    warn 'Last error was' .  Win32::OLE->LastError() . "\n";
    it should return an error string, not a code.

    Originally Posted by yakirllc
    I have another question, is there a way to set some environment variavbles in the running script and make it to use it.
    I need my script to set some new environment variables and then start running using the new environment variables.

    I know it has nothing to do with MSSQL or DB but it's another question I have and I'd like to have your help.

    Thanks alot again.
    Yep, piece of cake. Simply add to the built-in %ENV hash variable.
    Code:
    $ENV{'USER'} = 'foo';
    $ENV{PASSWORD} = 'bar';
    ...
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  6. #34
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    25
    Rep Power
    0

    Hi


    Thanks for the reply.

    Yeah, I've tried that before posting this question but its not working.

    My script has:
    $ENV{'ORACLE_HOME'} = "/software/oracle/PROD10gR2";
    $ENV{'LD_LIBRARY_PATH'} = "/software/oracle/PROD10gR2/lib:/usr/lib";

    and it still not working. The issue is like the following, I need to use the DBD::Oracle library and it's not in my user's path/environment variables. The way to do make my script know and use this library is by applying the above environment variables.

    It's not working.
    Do you know why?

    Thanks again.
  8. #35
  9. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    If DBD::Oracle was not installed under the @INC paths, then you need to add a use lib statement to tell perl where it's located.

    See: perldoc lib
  10. #36
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    25
    Rep Power
    0

    Hi


    Hi,

    Tried that too... :
    use lib '/software/oracle/PROD10gR2/lib/';
    use lib '/usr/lib';
    use DBI;
    use DBD::Oracle;

    Still not working...
    Never mind, I'll figure something out.

    Thanks.
  12. #37
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    Saying "It's not working" or "Still not working" is completely meaningless to us. You need to explain how it's failing and what error messages you received and the specific code used that is failing.

    This thread is getting absurdly long because you keep adding on new questions instead of starting new threads for the different questions.

    The use lib statements are to point to the custom locations where the perl modules are installed. They are not used to point to the Oracle libs or to set Oracle specific environment settings.
  14. #38
  15. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,643
    Rep Power
    4248
    Originally Posted by yakirllc
    Hi,

    Tried that too... :
    use lib '/software/oracle/PROD10gR2/lib/';
    use lib '/usr/lib';
    use DBI;
    use DBD::Oracle;

    Still not working...
    Never mind, I'll figure something out.

    Thanks.
    Ai caramba. You do NOT use DBD::Oracle; in your code directly. All that is needed is the use DBI; statement.
    Code:
    use DBI;
    
    my $dbh = DBI->connect('DBI:Oracle:myinstance', 'username', 'password') or die "DBI::errstr\n";
    # or
    # my $db_server  = 'myoracle.domain.com';
    # my $db_port = 1531;
    # my $instance = 'myinstance';
    # my $dbh = DBI->connect("DBI:Oracle://$db_server:$port/$instance', 'username', 'password') or die "DBI::errstr\n";
    The DBI module will pull the appropriate DBD module per the connection strings given. You do not need to use it explicitly.

    In case you're having a DBD issue, here's how you can list all the installed drivers in your system:
    Code:
    use DBI;
    
    my @drivers = DBI->available_drivers();
     
    foreach my $driver (@drivers) {
        print "Driver: $driver\n";
        my @data_sources = DBI->data_sources($driver);
        foreach my $data_source (@data_sources) {
            print "\tData Source is: $data_source\n";
        }
        print "\n";
    }
    If you don't see "Driver: Oracle" in the listing above, this means that DBD::Oracle isn't properly installed in your system. Make sure it is installed correctly before debugging further.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  16. #39
  17. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2009
    Posts
    1,947
    Rep Power
    1225
    You do NOT use DBD::Oracle; in your code directly.
    While it's not required to have a use DBD::Oracle; statement, I wouldn't agree that it's something that you do not do. It is often advantageous to have that use statement because you'll get a compilation error instead of a runtime error if there is a problem loading the module. Without the use statement, the module gets loaded at runtime during the connect statement, which may not be done until sometime later in the script.

    Personally, I prefer to find out as early as possible about any/all problems loading necessary modules.
  18. #40
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    25
    Rep Power
    0

    Thanks for the help


    Hi all,

    Thanks for the help and I'm sorry I made this thread too long.
    We can close the thread. I'll try everything you suggested and if It'll fail - I'll open a new thread.

    Thanks again, you all were very usefull and helping.
Page 3 of 3 First 123
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo