How to run SQL from OMB+

For any of you who wanted to be able to query the database from OMB+ in order to gather object metadata or whatever as part of your deployment scripts, you have no doubt noticed (to your frustration) that this functionality is not provided.
Sure, you can trigger execution of a sql/plus script as an external process, but that's hardly interactive now is it?
the good news is that OMB+ DOES provide access to the standard java package, which of course means that you can utilize the standard java.sql classes, which means - JDBC.
Here is a very simple starting point for you that provides simple connect, disconnect, and run query abilities. There is no exception handling and you'd need to add other functionality to execute prepared statements like procedure calls, or do DML like insert/update statement.
Still, I hope that you find it of use as a starting point - if you need it. For documentation on the java.sql interfaces, go to the Sun Java Docs page at: http://java.sun.com/j2se/1.3/docs/api/ and scroll down to the java.sql package in the top left pane.
Cheers,
Mike
package require java
proc oracleConnect { serverName databaseName portNumber username password } {
   # import required classes
   java::import java.sql.Connection
   java::import java.sql.DriverManager
   java::import java.sql.ResultSet
   java::import java.sql.SQLWarning
   java::import java.sql.Statement
   java::import java.sql.ResultSetMetaData
   java::import java.sql.DatabaseMetaData
   java::import oracle.jdbc.OracleDatabaseMetaData
   # load database driver .
   java::call Class forName oracle.jdbc.OracleDriver
   # set the connection url.
   append url jdbc:oracle:thin
   append url :
   append url $username
   append url /
   append url $password
   append url "@"
   append url $serverName
   append url :
   append url $portNumber
   append url :
   append url $databaseName
   set oraConnection [ java::call DriverManager getConnection $url ]
   set oraDatabaseMetaData [ $oraConnection getMetaData ]
   set oraDatabaseVersion [ $oraDatabaseMetaData getDatabaseProductVersion ]
   puts "Connected to: $url"
   puts "$oraDatabaseVersion"
   return $oraConnection
proc oracleDisconnect { oraConnect } {
  $oraConnect close
proc oraJDBCType { oraType } {
  #translation of JDBC types as defined in XOPEN interface
  set rv "NUMBER"
  switch $oraType {
     "0" {set rv "NULL"}
     "1" {set rv "CHAR"}
     "2" {set rv "NUMBER"}
     "3" {set rv "DECIMAL"}
     "4" {set rv "INTEGER"}
     "5" {set rv "SMALLINT"}
     "6" {set rv "FLOAT"}
     "7" {set rv "REAL"}
     "8" {set rv "DOUBLE"}
     "12" {set rv "VARCHAR"}
     "16" {set rv "BOOLEAN"}
     "91" {set rv "DATE"}
     "92" {set rv "TIME"}
     "93" {set rv "TIMESTAMP"}
     default {set rv "OBJECT"}
  return $rv
proc oracleQuery { oraConnect oraQuery } {
   set oraStatement [ $oraConnect createStatement ]
   set oraResults [ $oraStatement executeQuery $oraQuery ]
   # The following metadata dump is not required, but will be a helpfull sort of thing
   # if ever want to really build an abstraction layer
   set oraResultsMetaData [ $oraResults getMetaData ]
   set columnCount        [ $oraResultsMetaData getColumnCount ]
   set i 1
   puts "ResultSet Metadata:"
   while { $i <= $columnCount} {
      set fname [ $oraResultsMetaData getColumnName $i]
      set ftype [oraJDBCType [ $oraResultsMetaData getColumnType $i]]
      puts "Output Field $i Name: $fname Type: $ftype"
      incr i
   # end of metadata dump
   return $oraResults
#now to run a quick query and dump the results.
set oraConn [oracleConnect myserver orcl 1555 scott tiger ]
set oraRs [oracleQuery $oraConn "select name, count(*) numlines from user_source group by name" ]
#for each row in the result set
while {[$oraRs next]} {
  #grab the field values
  set procName [$oraRs getString name]
  set procCount [$oraRs getInt numlines]
  puts "Program unit $procName comprises $procCount lines"
$oraRs close
$oraConn close

Oracle may indeed have used OraTCL as the starting point for OMB+, but if so then they have clearly wrapped their own interface around it and hidden the original commands. Now, I suppose that it should be possible to add OraTcl as an external library, however the Oratcl distribution makes use of the TCL "load" command to load their binaries.
You will quickly find that Oracle has also disabled the standard TCL "load" command in OMB+, thus making very difficult to add third-party plug-in packages.
If you can find a pure-TCL script db interface similar to OraTcl to manage SQL*Plus connections that doesn't use any of the TCL commands that ORacle has disabled - well then you could probably get those to load as packages.
Or, like me, you could just use the supplied java interface and code your own as needed.
Cheers,
Mike

Similar Messages

  • How to run SQL from PL/SQL?

    hi,
    i want to run sql script from PL/SQL,
    in my PL/SQL,i have given the path within the double quotes,
    @"/usr/local/pbiace/current/bin/handle.sql" but while running the script im getting some exception.
    pls guide me.....

    What is your OS.
    First example, divide three part scritps and then
    cat beforepart.sql account.sql afterpart.sql | sqlplus user/password@connectstring
    type beforepart.sql+account.sql+afterpart.sql | sqlplus user/password@connectstring
    Second example, divide two part scripts.
    acc2.sql
    declare HandleN varchar(20);
    begin
    select pbhandlenamelower INTO HandleN from pb_handle where pbhandleid in(select max(pbhandleid)
    from pb_handle where ha_customerentityid in (select acct_customerentityid from account
    where acct_accountid = &1 )) AND pbmainhandleflag=1 ;
    do.pl('==============================') ;
    do.pl('Handle Name: ' || HandleN ) ;
    do.pl('==============================') ;
    EXCEPTION
    WHEN OTHERS THEN
    do.pl('No rows selected');
    END;
    exit
    main.sql
    set serveroutput on
    varaiable variable1 NUMBER
    DECLARE
    data varchar2(20);
    BEGIN
    data:='&1';
    select BI_ACCOUNTID into :variable1 from pb_bill_info where PBBTN=data;
    do.pl('BI_ACCOUNTID');
    do.pl('------------');
    do.pl(:variable1);
    end;
    @acc2 :variabl1
    Third Example
    create or replace directory SCRIPTS_DIR as 'path name'
    acc3.sql (Only 1 statement, don't include into-clause and ';')
    select pbhandlenamelower from pb_handle where pbhandleid in(select max(pbhandleid)
    from pb_handle where ha_customerentityid in (select acct_customerentityid from account
    where acct_accountid = :variable1 )) AND pbmainhandleflag=1
    main.sql
    set serveroutput on
    DECLARE
    data varchar2(20);
    variable1 NUMBER;
    HandleN varchar(20);
    p_sql varchar2(32000) := '';
    File_Handle UTL_FILE.FILE_TYPE;
    Read_line varchar2(4000);
    BEGIN
    data:='&1';
    select BI_ACCOUNTID into variable1 from pb_bill_info where PBBTN=data;
    do.pl('BI_ACCOUNTID');
    do.pl('------------');
    do.pl(variable1);
    File_Handle := UTL_FILE.FOPEN('SCRIPTS_DIR','acc3.sql','r');
    loop
    UTL_FILE.GET_LINE(File_Handle, Read_line);
    exit when no_data_found;
    p_sql := p_sql || Read_line || chr(32) ;
    end loop;
    UTL_FILE.FCLOSE(File_Handle);
    execute imediate p_sql into HandleN using varaiable1;
    do.pl('==============================') ;
    do.pl('Handle Name: ' || HandleN ) ;
    do.pl('==============================') ;
    EXCEPTION
    WHEN OTHERS THEN
    do.pl('No rows selected');
    END;
    Or Some many other Examples and those are maybe more simple, only if you would analyze your business requirements.

  • How to run SQL files from Java?

    Hi,
    Can someone point me towards a link on how to run sql files in Java? Thanks.
    P.S...if I've been completely blind please go easy on me!

    Sorry forgot the formating code thingy
    public static boolean executeScript(File script, Connection conn){
        boolean success = true;
        success = script.exists();
        if(success){
          DEBUG.print("ES::READING SCRIPT:" + script.getAbsolutePath());
          StringBuffer buffer = new StringBuffer();
          success=readScript(script,buffer);
          if(success){
            try{
              String creationScript = buffer.toString();
              Statement st = conn.createStatement();
              int start = 0;
              int end = 0;
              while (end != -1 && start < creationScript.length()) {
                end = creationScript.indexOf("GO", start);
                if (end != -1) {
                  DEBUG.print(creationScript.substring(start, end));
                  st.executeUpdate(creationScript.substring(start, end));
                  start = end + 2; //2 is the length of "GO"
              st.close();
            }catch(Exception e){
              success=false;
              DEBUG.printStackTrace(e);
        }else{
          DEBUG.print("ES::SCRIPT FILE DOES NOT EXISTS");
          success=false;
        return success;
      public static boolean readScript(File script, StringBuffer buffer){
        boolean success = true;
        DEBUG.print("RS:: reading file :" + script.getAbsolutePath());
        try{
          InputStreamReader isr = new InputStreamReader(new FileInputStream(script),"UTF16");
          int ch;
          while ( (ch = isr.read()) > -1) {
            buffer.append( (char) ch);
          if (isr != null)
            isr.close();
        }catch(Exception e){
          success=false;
          DEBUG.printStackTrace(e);
        return success;
      }

  • How to run report from context menu using XML Extensions?

    I have found an example how to run SQL command from context menu:
    <items>
    <folder type="TABLE">
    <name>UserDefined ContextMenus</name>
    <item TYPE="TABLE" reloadparent="true">
    <title>Create SYNONYM</title>
    <prompt type="check">
    <label>PUBLIC</label>
    <value>PUBLIC</value>
    </prompt>
    <prompt>
    <label>NEW SYNONYM NAME</label>
    </prompt>
    <sql>
    <![CDATA[CREATE #0# SYNONYM  #1# for "#OBJECT_OWNER#"."#OBJECT_NAME#"]]>
    </sql>
    <help>
    This action create a SYNONYM (optionally public) for the selected table.</help>
    <confirmation>
    <title>Confirmation</title>
    <prompt>SYNONYM "#1#" for "#OBJECT_NAME#" has been created.</prompt>
    </confirmation>
    </item>
    </folder>
    </items>
    </prompt>
    But instead of executing SQL command I need to show result page of report based on SELECT statement.

    Hi dz_r-
    Not sure exactly what you mean by "result page of report", but extensive documentation on the xml schema defining context menu actions is available at the schema location.
    &lt;items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://xmlns.oracle.com/sqldeveloper/3_1/dialogs"
      xmlns="http://xmlns.oracle.com/sqldeveloper/3_1/dialogs">
        &lt;!-- your declarations here -->
    &lt;/items>
    Brian Jeffries
    SQL Developer Team

  • How to run expdp from client ?

    Hi All,
    I tried searching google and forums for my issue but to no avail > How to run expdp from client side ....like in my laptop.
    Because currently our PROD database server has no space for expdp dump file. So I want it directed to my laptop which has an extenal USB of 1TB harddisk...via client EXPDP
    import data using impdp command
    Posted on: 08-May-2012 11:36, by user: 841731 -- Relevance: 53% -- Show all results within this thread
    below command is correct or not? if it is not correct could you please send me the correct command. impdp user/pass@databasename schemas=sourceschemaname remap_schema=sourceschemaname:destinationschemaname ...
    System generated Index names different on target database after expdp/impdp
    Posted on: 30-May-2012 11:58, by user: 895124 -- Relevance: 43% -- Show all results within this thread
    After performing expdp/impdp to move data from one database (A) to another (B), the system name generated indexes has different ...
    [ETL] TTS vs expdp/impdp vs ctas (dblink
    Posted on: 08-May-2012 21:10, by user: 869578 -- Relevance: 39% -- Show all results within this thread
    (table : 500 giga, index : 500 giga), how much faster is TTS (transportable tablespace) over expdp/impdp, and over ctas (dblink) ? As you know, the speed of etl depends on the hardware capacity. (io ...
    Oracle Client
    Posted on: 21-Jun-2012 22:47, by user: Sh**** -- Relevance: 32% -- Show all results within this thread
    Hi Guys, Please can you guys elaborate the difference between Oracle Client and Oracle Instant Client. Also, please can you advise from where I can download the Oracle normal ...
    Oracle 10g Client
    Posted on: 05-Jun-2012 10:11, by user: dzm -- Relevance: 26% -- Show all results within this thread
    to search at oracle site and this forum, but i wasn't able to find a link to download the oracle 10g client. I really need especificaly the 10g version. Anybody know the link or another way to download ...
    9i client to access 11g database
    Posted on: 22-Jun-2012 07:31, by user: kkrm333 -- Relevance: 24% -- Show all results within this thread
    Hi, Can i access a 11g database using 9i client? Thanks,
    SQLplus in Oracle Client
    Posted on: 14-Jun-2012 00:36, by user: Tim B. -- Relevance: 24% -- Show all results within this thread
    Hi, I tried to install an 11g oracle client in linux. As I've compared the files with the files when you install using the oracle instant ...
    Re: Information on Oracle Client 11202-1.1.4-6
    Posted on: 05-Jun-2012 03:33, by user: 898763 -- Relevance: 23% -- Show all results within this thread
    Actually thats the client requirement
    Analysing the performance of a single client
    Posted on: 28-Mar-2012 02:05, by user: 880172 -- Relevance: 23% -- Show all results within this thread
    timeouts even on some of the simplest queries. I want to try and get some data about how just this one client is performing and what it’s doing, but everything Google has thrown up so far is orientated around ...
    to make client connection as sys
    Posted on: 12-Jun-2012 22:04, by user: user11221081 -- Relevance: 23% -- Show all results within this thread
    Dear gurus can i connect to my server from my client machine with sysdba without giving sys password i have connected in different ways as sys@abc ...Thanks a lot.

    Though you can initiate the binary from your client side but for the file creation, there is no other way but to store it on the server side. So your best bet would be to get some space free on the server side of yours.
    Aman....

  • How to run .sql file in tsql or powershell

    Hi All,
    HOw to run .sql file inside the TSQL or powershell using with IF else condition. This below query works fine but when i executing through the SQL Agent it's geeting an error.Please could help how to run through the SQL agent already using execution type
    in agent as 'Operating system(CmdExec)'
    Declare @computerName varchar(100), @InstanceName varchar(50)                             
    SET @ComputerName = REPLACE(CAST(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS varchar),'\','$')  
    SET @InstanceName = REPLACE(CAST(SERVERPROPERTY('instancename') AS varchar),'\','$')
    IF (@InstanceName = 'SQL2008R2')
    Begin  
    :r C:\BackupFolder\Test1.sql    
    :r C:\BackupFolder\Test2.sql    
    End
    IF (@InstanceName = 'SQLINS2')
    BEGIN
    :r C:\BackupFolder\Test3.sql
    END
    IF (@InstanceName = 'SQL2012')
    BEGIN
    :r C:\BackupFolder\Test4.sql
    END
    Thansk in Advance
    A-ZSQL

    In T-SQL, you can try using sqlcmd to invoke sql file
    if @@SERVERNAME='abcd'
    begin
    Master..xp_cmdshell 'sqlcmd -S <ServerName> -i BackupDetails.sql -E'
    end
    OR 
     PowerShell 
    Load the snapins
    Add-PSSnapin SqlServerCmdletSnapin100
    Add-PSSnapin SqlServerProviderSnapin100
    Function Get-SqlInstances {
    Param($ServerName = '.')
    $localInstances = @()
    [array]$captions = gwmi win32_service -computerName $ServerName | ?{$_.Name -match "mssql*" -and $_.PathName -match "sqlservr.exe"} | %{$_.Caption}
    foreach ($caption in $captions) {
    if ($caption -like "MSSQLSERVER") {
    $localInstances += $ServerName
    } else {
    $temp = $caption | %{$_.split(" ")[-1]} | %{$_.trimStart("(")} | %{$_.trimEnd(")")}
    $localInstances += "$ServerName\$temp"
    $localInstances
    $instance=Get-SqlInstances -ServerName HQDBSP17
    foreach($i in $instance)
    if($i -like 'CRM2011')
    write-host 'CRM Database'
    invoke-sqlcmd -inputfile 'F:\PowerSQL\test.sql' -ServerInstance 'abcd'
    if( $i -like 'SQL2012')
    write-host 'SQL 2012 instance'
    invoke-sqlcmd -inputfile 'F:\PowerSQL\test.sql' -ServerInstance 'abcd'
    --Prashanth

  • How to run report from form using run_object_report

    I AM USNING FORMS9I/REPORTS 9I , HOW TO RUN REPORT FROM FROM USING RUN_REPORT_OBJECT AND HOW
    TO PASS PARAMETER AS WE DID IN RUN_REPORTS PLEASE HELP ME

    here an example !
    I hope this example you can use it
    PROCEDURE pr_reporte IS
    BEGIN
    DECLARE
         repid REPORT_OBJECT;
    v_rep VARCHAR2(100);
    rep_status Varchar2(20);
    d1 DATE;
    d2 DATE;
    BEGIN
         d1 := :GLOBAL.DIA_INI;
         d2 := :GLOBAL.DIA_FIN;
         repid := find_report_object('rep_lab02');
         SET_REPORT_OBJECT_PROPERTY(repid,REPORT_OTHER,'p_fec_uno='||to_char((add_months(last_day(d1),-1) +1),'DD/MM/YYYY')||' '||
         'p_fec_dos='||to_char(d2,'DD/MM/YYYY'));
         SET_REPORT_OBJECT_PROPERTY(repid,REPORT_DESFORMAT,'pdf');
         v_rep := RUN_REPORT_OBJECT(repid);
         rep_status := report_object_status(v_rep);
         WHILE rep_status in ('RUNNING','OPENING_REPORT','ENQUEUED') LOOP
              rep_status := report_object_status(v_rep);
         END LOOP;
         IF rep_status = 'FINISHED' then
              WEB.SHOW_DOCUMENT('/reports/rwservlet/getjobid'||substr(v_rep,instr(v_rep,'_',-1)+1)||'?'||'server=repserver','_blank');
         ELSE
              ventana('E','error reporte no encontrado','S');
         END IF;
    END;
    END;
    The 'rep_lab02' is the name of the report that you give in the node reports
    p_fec_uno and p_fec_dos they are the parameters in the report
    repserver is the name of server created with rwserver
    Greetings

  • How to run workflow from Developer studio ?

    Hi Guys,
    I searched for a work item type in the developer studio and it showed the results, but could not find out how to run it from there.. I know we can run it from there.. There is no run button or options available.
    Do i need to setup some profile options ?
    Any help in this is highly appreciated !!
    Thanks,
    Sathish

    Hi,
    Are you logged in as the Workflow Administrator or a user who has been assigned that responsibility?
    Have a look on the Administration tab and it will show you who is configured as the admin.
    HTH,
    Matt
    WorkflowFAQ.com - the ONLY independent resource for Oracle Workflow development
    Alpha review chapters from my book "Developing With Oracle Workflow" are available via my website http://www.workflowfaq.com
    Have you read the blog at http://www.workflowfaq.com/blog ?
    WorkflowFAQ support forum: http://forum.workflowfaq.com

  • How to Run scenario from the web using HTTP web page?

    Hi guys
    Please let me know How to Run scenario from the web using HTTP web page?
    Regards
    Janakiram

    Hi Janakiram,
    ODI provides web based UI for running the scenarios using Metadata Navigator (read only of ur ODI components) and Lighweight designer (u can edit the mapping here).
    Please explore how to install metadata navigator in ODI and have a look at ODI Setup document for more information.
    Thanks,
    Guru

  • How to run notepad from a web application

    hi
    can any body know,how to run notepad from a web application under tomcat

    You already asked this question:
    http://forum.java.sun.com/thread.jspa?threadID=5150005&messageID=9561597
    Obviously running notepad on the clients PC is not possible (ignoring active x)

  • How to run import from Unix Oracle 8.0.5 database with Windows Oracle client?

    How to run import from Unix Oracle 8.0.5 database via network with Windows Oracle client? Is it possible? When I try to do it Oracle client just hangs... If not which ones are compatible Aix or Solaris to Unix or it must be a Unix client to connect to Unix Oracle database. Thank's for any help.

    Hi,
    In our project we are using this type. Since in this project server in UNIX(DEC) and client is running on windows. We have created a listener which always listen requests from client and doing the according to the request.
    Step1. create a request table, where u are inserting ur request.
    step2. create PRO*C proram, which is listening request on the table. If there is any request, call the imp (executable). This is happening on server side.
    Benifit. U can make a request from cleint and ftp the file client sit.
    Are u interested in more details and code, pls send a mail to me
    ---- Boby Jose Thekkanath
    [email protected]
    Dharma Computers(p) Ltd. Bangalore.
    null

  • How to run SQL entered in a table.

    Hi,
    I have a table and in that table I have rows with sql commands, I want to select a single row I mean a single sql statement to run. How to achieve this from forms 10g ? I will retrieve that row from table, get the sql in a variable and how to run that sql in a variable. Please let me know. Thank you. Also let me know whether I need to have a semicolon in the row at the end of the sql command in that row of sql command.
    I want to use that sql in create_group_from_query command to populate list of values.
    Any Gurus out there ?

    Hi Jowal,
    I was back after many days, I tried your sql code, I populated it in variable with same size characters and passed it to the list item, but it is not running ! Can you please let me know what is the problem ? When I hard code sql then only the query is running and populating the list otherwise not. There are no errors displayed. The list item is just not getting populated. Forms 10g patchset 10.1.2.0.2 oracle database 11g on windows 7
    Please help.

  • Run SQL from UNIX

    How could I run sqlplus from an Unix machine?

    If want to Install
    1. Need to Install Oracle Client
    2. Use SQL *PLUS
    or
    If dont want to install
    1. Use iSQLPLUS

  • Information on how to run SQL queries on the CUCM itself please

    Good Day All,
    I need to run an sql query on the CUCM to list all of my directory numbers, their partition, and their external mask values.
    I came across this excerpt below earlier so I have a bit of an idea how to do it but iw would be great to see some other examples of sql queries.
    Any assistance is most appreciated.
    Also, is there a document somewhere to tell me how to run these queries?
    Thanks in advance
    Regards
    Amanda
    Currently Being Moderated
    05/04/2011 5:18 AM (in response to Joshua Royle)
    Re: Is there a way of pulling a report off CM showing all phones that have diverts on?
    Try if running this SQL query from the CLI helps you, it should list all DN's that have CFA enabled to VM or a DN:
    run sql select dnorpattern,cfadestination,cfavoicemailenabled from CallForwardDynamic c, numplan n where c.fknumplan = n.pkid and (cfadestination != '' or cfavoicemailenabled ='t')

    Hi Amanda
    Basically it's standard SQL, so it wouldn't hurt to google 'informix select statements' and do a little reading to get the basics. There are millions of permutations of queries so it's a matter of understanding the syntax, and then applying that to the database in question. The only difference when running commands from the CLI are that:
    - You prefix the standard informix SQL statement with 'run sql'
    - You don't get any help from CUCM with the syntax, so you might be well advised to use something that understands SQL a little and colorises it as you type, and then paste the resulting commands into the CUCM SSH window. I use a text editor named JEdit, if you create a text file and save it as a file ending in .sql it will highlight your syntax.
    - Other programs are available that do reasonable syntax highlighting (e.q. SquirrelSQL) that are designed for querying the DB directly, but you can't actually query directly against the DB for security reasons. You'd still have to copy/paste the commands.
    Now... to understand the DB you'll need a reference describing all the tables etc. This is here:
    http://www.cisco.com/en/US/products/sw/voicesw/ps556/products_programming_reference_guides_list.html
    Pick your version of CUCM and download the 'Data Definition' document.
    A few notes on the command:
    run sql : is just the CLI command that tells the shell to run the following text as SQL.
    select : the SQL command to retrieve data
    dnorpattern,cfadestination,cfavoicemailenabled : the column names to retrieve
    callforwarddynamic c, numplan n : the names of two tables, and the abbreviations you want to refer to them as
    where c.fknumplan = n.pkid : this tells SQL to return values from the two tables where these fields match up. In the data definition you'll see notes that c.fknumplan (i.e. the fknumplan column in the callforwarddynamic table, as noted by the c. prefix) refers to the PKID column in the numplan field. This is a very standard type of join in the CCM DB.
    and (cfadestination != '' or cfavoicemailenabled ='t') : another clause, basically in this query we want to see only rows where cfadestination isn't blank or cfavoicefmailenabled is set to 't' for true).
    Most tables are linked in one of two ways in this database:
    - a column prefixed 'fk' refers to the pkid field (there is always only one pkid field per table) in the table following the 'fk' prefix. E.g. above fknumplan refers to the numplan table, pkid field. fkdevice would refer to the device table, pkid field.
    - a column prefiex 'tk' refers usually to an enum table which is prefixed with 'type'. This is a table that maps the number value in the 'tk' field to a string. An example would be tkmodel - this represents the phone physical model type (e.g. 7962), and maps to a table called typemodel, and the 'enum' column in that table.
    Regards
    Aaron HarrisonPrincipal Engineer at Logicalis UK
    Please rate helpful posts...

  • Remotely running SQL from PowerShell

    Hi
    I work for a Software House where checking files versions, running SQL to check tables is becoming run-of-the mill :)
    I'm very new to PowerShell so far and have just been playing about to find that I can remotely check file-versions ok. Now onto the other side of the coin....running SQL to check tables is the next thing I need to learn.
    Just for a heads-up. Most of the servers I connect to are running MS SQL Server 2003 (unfortanately) which is why I want to remotely check the servers without connecting in via Remote Desktop Session. With MS Server 2003, if I use a Remote Desktop
    Session, I've found that I would have to download PowerShell (v1) and then have to configure it to allow it to run my .ps1 scripts which would also become cumbersome.
    Can anyone give me a start and say how to remotely connect to and SQL database and then run a simple SELECT statement from PowerShell please. I can then build my powershell scripts up from there.
    Kind Regards
    Matt

    Hi
    I've tried this script but get the error below if anyone can help.
    # Get SQL rows if they exist
    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection
    $SqlConnection.ConnectionString = "Server=\\10.1.2.3;Database=THEHOUSE;Integrated Security=True;User Id=Joe123;Password=password123"
    $SqlConnection.Open()
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.CommandText = "SELECT * FROM TABLEX WHERE TRANS_TYPE='ACG'"
    $SqlCmd.Connection = $SqlConnection
    $dbname = $SqlCmd.ExecuteScalar()
    $SqlConnection.Close()
    Write-output "Database is " $dbname
    The error I get is:
    Exception calling "Open" with "0" argument(s): "A network-related or instance-specific error occurred while
    establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the
    instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL
    Network Interfaces, error: 25 - Connection string is not valid)"
    At C:\PS1scripts\Get SQL table data.ps1:5 char:1
    + $SqlConnection.Open()
    + ~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : SqlException
    Exception calling "ExecuteScalar" with "0" argument(s): "ExecuteScalar requires an open and available
    Connection. The connection's current state is closed."
    At C:\PS1scripts\Get SQL table data.ps1:9 char:1
    + $dbname = $SqlCmd.ExecuteScalar()
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : InvalidOperationException

Maybe you are looking for