PowerShell and SQL Server Trigger

I had the following trigger written but apparently our IT department has not set up server/account or whatever needs to be done to use SQL Server's DB Mail.
ALTER TRIGGER [dbo].[Faxiles_Trigger]
ON [dbo].[DummyFQF]
AFTER INSERT
AS
BEGIN
DECLARE @tableHTML NVARCHAR(MAX) ;
SET @tableHTML =
N'<H1>Fax Error Report</H1>' +
N'<table border="1">' +
N'<tr><th>[FileID]</th>
<th>[FaxID]</th>
<th>[FilePath]</th></tr>' +
CAST ( (
SELECT
td=T1.[FileID],' ',
td=T1.[FaxID],' ',
td=T1.[FilePath],' '
FROM
FaxQueueFiles as T1
INNER JOIN
FaxQueue as T2
ON
T1.[FaxID] = T2.[FaxID]
WHERE
T2.[DateAdded] between Dateadd(hour,-1,GETDATE()) and Getdate()
AND
T1.[FilePath] NOT LIKE 'C:\%'
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
EXEC msdb.dbo.sp_send_dbmail
@recipients='[email protected]',
@subject = 'Fax Error Report',
@body = @tableHTML,
@body_format = 'HTML';
END
How can I instead make the trigger envoke/call a powershell script that can perform the same query and send an e-mail?
Apparently we do have e-mail functionality for our scripts, so that part I can just copy/paste from a pre-existing script. What I don't know how to do (since I am brand new to powershell scripting) is save the results of a query into a HTML-f0rmatted table
as the body of the e-mail like I did with SQL.
Thanks in advance for any assistance you can provide.
# Connect to the database.
$dbConnSites = New-Object System.Data.SqlClient.SqlConnection("Data Source=localhost;Initial Catalog=Main;Integrated Security=SSPI");
# Open database connection.
$dbConnSites.Open();
# Query String
$dbQry_BadTIFs = "
SELECT
T1.[FileID], T1.[FaxID], T1.[FilePath]
FROM
Main.FaxQueueFiles as T1
INNER JOIN
FaxQueue as T2
ON
T1.FaxID = T2.FaxID
WHERE
T2.[DateAdded] between DATEADD(hour,-1,GETDATE()) and GETDATE()
AND
T1.[FilePath] NOT LIKE 'C:\%'
# Create an SQL Command to execute the above query using the database connection object
$dbGetBadTIFs = New-Object System.Data.SqlClient.SqlCommand(dbQry_BadTIFs, $dbConnSites);
# Reader object to read the results of the executed SQL Command
$dbGetBadTIFsReader = $dbGetBadTIFs.ExecuteReader();
# Loop through the results of GetBadTIFs
while ($dbGetBadTFIsReader.Read())
# Close all the database connections
$dbConnSites.Close();
The above code is what I've come up with so far.... So within my while loop I presume the E-mail will some how be generated?
Should I declare a new string object and concatenate within the loop?
# Start the HTML Table for the e-mail
$str_EmailBody = "
<H1>Fax Error Report<H1>
<TABLE border=`"1`">
<TR>
<TH>[FileID]</TH>
<TH>[FaxID]</TH>
<TH>[FilePath]</TH>
</TR>
</TABLE>
# Loop through the results of GetBadTIFs
# to fill out the HTML Table
while ($dbRdr_GetBadTIFs.Read())
$str_EmailBody += "???";
# Finish the HTML Table for the e-mail
$str_EmailBody += "
</TR>
</TABLE>";
-Nothing to see. Move along.

Hi Blacksaibot,
If you want to query the sql cmd and send eamil with the result, please refer this script, to save the result of the query, plrease try to create a sql datatable:
PowerShell Display Table In HTML Email
If I have any misunderstanding, please let me know.
Best Regards,
Anna

Similar Messages

  • Installing BAM with Biztalk Server 2013 and SQL server 2012

    Hello All,
    I have to work on BAM with BizTalk Server 2013 and SQL server 2012 , is BAM already comes with BizTalk server installation ?
    Will I needs to explicitly install that ? from where I can get the installer for BAM ?
    What else I will needs to work on BAM ?
    Note : I want to handle Exceptions in BAM ....how to do that ?
    Thanks,
    Nitin.
    Thanks and Regards, Nilesh Thakur.

    Hi,
    BAM is available with BizTalk, all you need is to select it and install .
    Refer the
    Installation Guide available on MSDN or follow the blog: http://sandroaspbiztalkblog.wordpress.com/2013/05/05/biztalk-2013-installation-and-configuration-important-considerations-before-set-up-the-server-part-1/
    Maheshkumar S Tiwari|User
    Page|Blog|BizTalk
    Server : Scheduling Orchestration using Trigger Message

  • Can I call a Java program from a SQL Server Trigger?

    Hello,
    I want to encrypt some data in a database column in SQL Server. Today I am using java code to encrypt the value and store it in the database using JDBC.
    Now I want to use a VB client to store the encrypted value in the SQL Server DB. Since the encryption is handled by a java class, can I write a trigger in SQL Server that while inserting the raw data, calls the java class for encrypting the value and then inserts the encrypted value into the column?
    In general, is it possible to call a java class from a SQL Server trigger?
    Thanks
    Bipin

    Here are 3 examples of code for insert, update and delete:
    CREATE TRIGGER [PLI_INSERT_TRIGGER] ON [dbo].[PLI]
    FOR INSERT
    AS
    Declare @cmd sysname, @code sysname, @list sysname
         Select @code = PLI_K_COD, @list = PLI_K_LISTINO from inserted
         Set @cmd = 'java mirrorDb.Copy PLI INSERT ' + @code + ' ' + @list
         EXEC master..xp_cmdshell @cmd
    CREATE TRIGGER [PLI_UPDATE_TRIGGER] ON [dbo].[PLI]
    FOR UPDATE
    AS
    Declare @cmd sysname, @code sysname, @list sysname
         Select @code = PLI_K_COD, @list = PLI_K_LISTINO from inserted
         Set @cmd = 'java mirrorDb.Copy PLI UPDATE ' + @code + ' ' + @list
         EXEC master..xp_cmdshell @cmd
    CREATE TRIGGER [PLI_DELETE_TRIGGER] ON [dbo].[PLI]
    FOR DELETE
    AS
    Declare @cmd sysname, @code sysname, @list sysname
         Select @code = PLI_K_COD, @list = PLI_K_LISTINO from deleted
         Set @cmd = 'java mirrorDb.Copy PLI DELETE ' + @code + ' ' + @list
         EXEC master..xp_cmdshell @cmd
    you must go "sql server entreprise manager" right click on the table you want to add triggers and select: all activities, manage triggers.
    You have 3 examples: for an insert, for an update and for a delete
    ON [dbo].[PLI] specify the table on which you want to setup trigger.
    FOR DELETE, INSERT, UPDATE specify the event.
    The Declare statement create the variables in which I want to put some values to pass to the java program, for example which table, which event, which key fields.
    the "Select @code = PLI_K_COD, @list = PLI_K_LISTINO from inserted" set the variables with the value of the columns of the table I am interested to read from my java program, for example the variable @code receive the value of the column pli_k_kod (is the key) of the table PLI.
    The "Set @cmd = 'java mirrorDb.Copy PLI DELETE ' + @code + ' ' + @list " prepared the variable @cmd with the java command followed by the package.classname and parameters.
    The EXEC launch the command to the operating system.
    Daniele

  • What is the different between Sharepoint fast search service and Sql server fulltext search?

    HI ,
    I want to kow what is the different between Sharepoint fast search service and Sql server fulltext search?
    Or Can I abstract the Sharepoint fast search from the Sharepoint platform as a isolate component?
    Thank you.
    James

    They are very, very different beasts.
    Firstly FAST Search for SharePoint is the old name for the product and is only relevant for SharePoint 2010 not 2013. It got merged into the standard SharePoint search for the 2013 release.
    SharePoint search is aimed at providing a Bing or Google like experience for your intranet content, as well as providing some nifty features that are purely SharePoint releated along the way. That means it can crawl SharePoint content, file shares,
    outlook mailboxes, internal and external websites and probably fifty other different things if you really tried. Whilst i'm not an expert on SQL full text search I believe it's intended to provide a search feature for content held within SQL databases
    and tables.
    Can you run SharePoint purely for Search? Yes, definitely.

  • Matching data types b/w oracle and sql server

    anyone here knows if there is a list of data types supported by both oracle and sql server (regardless of releases & versions?
    an immediate response would be highly appreciated.
    thanks.

    Hi,
    The following post might be of assistance to you:
    http://msdn.microsoft.com/en-us/library/ms151817.aspx
    If this is what you're looking for, then mark the question as answered and closed.
    Regards,
    Naveed.

  • SMS_SRS_REPORTING_POINT - Error retrieving folders with SCCM 2012 and SQL Server 2008 R2 SP2

    Hi:
    According to all the Reporting Services logs my Reporting Point was setup correctly.  When I try and run any report I see the entries below in the srsrp.log on the SQL Server.  The report names show up in the Console but when I right any of the
    listed reports I get errors and no report runs.
    I am running SQL Server 2008 R2 SP2 on a remote server.  SQL is installed on its own server.  There is no firewall between the Configuration Manager server and SQL Server.
    Thanks.
    Mark
    (!) Error retrieving folders - [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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because
    connected host has failed to respond.)].   SMS_SRS_REPORTING_POINT
    1/25/2013 9:15:07 AM    4532 (0x11B4)
    No folder configuration information found.     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:15:07 AM   
    4532 (0x11B4)
    Next security configuration at [1/25/2013 9:22:42 AM]
    SMS_SRS_REPORTING_POINT 1/25/2013 9:15:07 AM   
    4532 (0x11B4)
    Root Folder exists     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:15:07 AM   
    4532 (0x11B4)
    Successfully checked that the SRS web service is healthy on server DBSCCM.LOCAL    
    SMS_SRS_REPORTING_POINT 1/25/2013 9:15:07 AM 
    4532 (0x11B4)
    Waiting for changes for 1 minutes  
    SMS_SRS_REPORTING_POINT 1/25/2013 9:15:07 AM   
    4532 (0x11B4)
    SRSRP registry key change notification triggered.    
    SMS_SRS_REPORTING_POINT 1/25/2013 9:15:16 AM   
    4532 (0x11B4)
    Waiting for changes for 1 minutes  
    SMS_SRS_REPORTING_POINT 1/25/2013 9:15:16 AM   
    4532 (0x11B4)
    Timed Out...     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:16:16 AM   
    4532 (0x11B4)
    Reporting Services URL from Registry [http://dbsccm/ReportServer/ReportService2005.asmx] 
    SMS_SRS_REPORTING_POINT 1/25/2013 9:16:16 AM 
    4532 (0x11B4)
    Reporting Services is running
    SMS_SRS_REPORTING_POINT 1/25/2013 9:16:16 AM   
    4532 (0x11B4)
    Retrieved datasource definition from the server.     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:16:16 AM   
    4532 (0x11B4)
    Retrieved datasource definition from the server.     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:16:16 AM   
    4532 (0x11B4)
    Updating data source {5C6358F2-4BB6-4a1b-A16E-8D96795D8602} at ManagedDesktops_MD1 
    SMS_SRS_REPORTING_POINT 1/25/2013 9:16:16 AM 
    4532 (0x11B4)
    (!) Error retrieving folders - [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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because
    connected host has failed to respond.)].   SMS_SRS_REPORTING_POINT
    1/25/2013 9:17:40 AM    4532 (0x11B4)
    No folder configuration information found.     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:17:40 AM   
    4532 (0x11B4)
    Next security configuration at [1/25/2013 9:22:42 AM]
    SMS_SRS_REPORTING_POINT 1/25/2013 9:17:40 AM   
    4532 (0x11B4)
    Root Folder exists     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:17:40 AM   
    4532 (0x11B4)
    Successfully checked that the SRS web service is healthy on server DBSCCM.LOCAL    
    SMS_SRS_REPORTING_POINT 1/25/2013 9:17:40 AM 
    4532 (0x11B4)
    Waiting for changes for 1 minutes  
    SMS_SRS_REPORTING_POINT 1/25/2013 9:17:40 AM   
    4532 (0x11B4)
    Timed Out...     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:18:40 AM   
    4532 (0x11B4)
    Reporting Services URL from Registry [http://dbsccm/ReportServer/ReportService2005.asmx] 
    SMS_SRS_REPORTING_POINT 1/25/2013 9:18:40 AM 
    4532 (0x11B4)
    Reporting Services is running
    SMS_SRS_REPORTING_POINT 1/25/2013 9:18:40 AM   
    4532 (0x11B4)
    Retrieved datasource definition from the server.     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:18:40 AM   
    4532 (0x11B4)
    Retrieved datasource definition from the server.     
    SMS_SRS_REPORTING_POINT 1/25/2013 9:18:40 AM   
    4532 (0x11B4)
    Updating data source {5C6358F2-4BB6-4a1b-A16E-8D96795D8602} at ManagedDesktops_MD1 
    SMS_SRS_REPORTING_POINT 1/25/2013 9:18:40 AM 
    4532 (0x11B4)

    Hi:
    Windows Firewall is off on both systems.
    I can ping the Configuration Manager server from the SQL Server by netbios name, ip address and fully qualified domain name.   I can ping the SQL Server from the Configuration Manager server by netbios name, ip address and fully qualified domain
    name.
    I have uninstalled and installed the Reporting Point Service a couple of times and everything looks fine according to the logs after the install finishes but these errors only appear each time I try and Run a report.
    Mark

  • Unable to connect to report server - on Win 8.1 and SQL Server 2014

    unable to connect to report server on  Win 8.1 and SQL Server 2014 version
    Microsoft SQL Server 2014 - 12.0.2000.8 (Intel X86)
        Feb 20 2014 19:20:46
        Copyright (c) Microsoft Corporation
        Express Edition on Windows NT 6.3 <X64> (Build 9600: ) (WOW64)
     Thanks

    Hi,
    I suggest you check out the following article for the steps of installing
    Database Engine Services and SQL Server Reporting Service.
    http://msdn.microsoft.com/en-us/library/ms143711.aspx
    Best Regards,
    Tracy
    Tracy Cai
    TechNet Community Support

  • How can I connect to Oracle and SQL server at the same time?

    I have been trying to find a way to connect to Oracle Database through the developer 2000 and SQL server at the same time. I need to return some data from Oracle Database and some from the Sql Server Database. And update both through SQL. I find there is such a thing as the Oracle Transparent Gateway for SQL server. I can't find it on any of my CD's or through OTN downloadable files. If anyone can point me where to get this. Or tell of another way this can be accomplished I would appreciate it. TIA.
    [email protected]

    I have been trying to find a way to connect to Oracle Database through the developer 2000 and SQL server at the same time. I need to return some data from Oracle Database and some from the Sql Server Database. And update both through SQL. I find there is such a thing as the Oracle Transparent Gateway for SQL server. I can't find it on any of my CD's or through OTN downloadable files. If anyone can point me where to get this. Or tell of another way this can be accomplished I would appreciate it. TIA.
    [email protected]
    As far as I know you have 3 options depending on your specifications. I don't think option #3 will work if you need to actually join a
    SQL Server table to an Oracle table.
    1. Oracle Transparent Gateway. I haven't used the Oracle Transparent Gateway but my understanding is that Oracle gateways are
    separate purchased products from Oracle. I've never seen any free/development versions of it anywhere. You'll need to contact
    your Oracle sales rep about it.
    2. Heterogeneous Connectivity. There's something called Heterogeneous Connectivity that could work for you - depends on what
    version of Oracle you're on and what OS. You basically set up an ODBC data source on the Oracle server and modify the listener.ora
    and tnsnames.ora files. You can then create a database link to SQL Server just like you would to any other Oracle database. You can
    check your Oracle documentation for how this works. There's also some very good documents on Metalink that tell you how to do this
    as well as a Heterogeneous Connectivity forum on this site.
    3. Use the exec_sql package available in Developer 2000. This allows you to open and execute cursors to remote databases within
    Developer. We have an account validation process that uses this - when a person enters an account number in a form while logged
    into Oracle it validates the account is valid in our main accounting DB2 database. We also pull HR information from DB2 into Oracle
    this way. If you're using Forms 6i exec_sql is a built-in command, in Forms 5.0 and 5.5 you have to add it as an attached library to
    the form. I think you also need the OCA options installed from the Developer software to have access to the library in Forms 5.0 and
    5.5. The library will be in the $ORACLE_HOME\oca20\plsqllib directory for these versions. The Developer documentation should have
    additional information.
    HTH

  • Linked Server error: Login Failed for user 'NT AUTHORITY\ANONYMOUS LOGON' between sql server 2005 32 bit and sql server 2012 64 bit

    Hi All,
    Here the linked server is created between sql server 2012 64 bit and sql server 2005 32 bit. I am getting the below error  when i try to access linked server from third server. I have created linked from Instance 1 to Instance 2. When i access it from
    instance 3 i am getting the below error. SPN setting has been done between these 2 servers. Also the option 'Trust the delegate' is enabled for the both the service account. 
    'Login Failed for user 'NT AUTHORITY\ANONYMOUS LOGON' 
    Appreciate your quick response. 
    Vikas.M.S

    Hello,
    Please read the following resources:
    http://www.databasejournal.com/features/mssql/article.php/3696506/Setting-Up-Delegation-for-Linked-Servers.htm
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/ea26de43-4c6b-4991-86d7-e1578f107c92/linked-server-login-failed-for-user-nt-authorityanonymous-logon?forum=sqldataaccess
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Compatability:  CR 2008, VS 2005 and SQL Server 2008 on WINDOWS 7

    Crystal Reports 2008,  Visual Studio 2005 and SQL Server 2008 all play nice together on a VISTA or XP box.  But we cannot get a connection when we switch the OS to WIN 7.   I tried to get a connection via the report designer.  Is this combination of technologies currently supported?
    Thanks.

    Hi, Jeff;
    See the [Platforms|http://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/00225757-ab5c-2c10-c1a8-fb9f9f0f4ac2] document for CR 2008. You need Service Pack 2 to run on Windows 7.
    If you already have SP 2, then what happens when you try to make a connection?
    Regards,
    Jonathan
    Follow us on Twitter u2013 http://twitter.com/SAPCRNetSup

  • I want to use the SQL Toolkit of NI and SQL Server as my databasis on a server. Do I need to install a client in each computer I want to handle the data into SQL tables or I need only a ODBC driver?

    I want to use the SQL Toolkit of NI and SQL Server as my databasis on a server. Do I need to install a client in each computer I want to handle the data into SQL tables or I need only a ODBC driver?

    You only need the ODBC driver on each computer. If you are distributing the SQL Toolkit app as an executable and do not install the whole toolkit on each computer, you'll need the SQL Toolkit support files. This is about a dozen files. You can get the list at http://digital.ni.com/public.nsf/websearch/b814be005f9da9258625658700550c75?OpenDocument.

  • SharePoint 2013 and SQL Server AlwaysOn - HA

    Hi guys,
    Please help!
    I need to setup SP13 server on SQL 2012 AlwaysOn (on sql01 and sql02). The HA AlwaysOn group already configured by DB team on these 2 replica with and called SP_AOAG  alias
    My question is can I use this alias to setup SharePoint  or I need to configure the HA AlwaysOn group for SgharePoint  as suggested in the article below:
    http://blogs.msdn.com/b/sambetts/archive/2013/04/24/sharepoint-2013-and-sql-server-alwayson-high-availability-sharepoint.aspx
    Any advice greatly appreciated . 
    BalaiP

    You do not want to use a SQL Alias with an AG Listener. Just point SharePoint straight at the AG Listener. You will need to manually add any accounts to non-primary instances. You do not need to add them to individual databases, of course. You will also
    need to manually set MAXDOP to 1 on non-primary instances.
    Trevor Seward
    Follow or contact me at...
    &nbsp&nbsp
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • [Forum FAQ] How do I disable all subscriptions without disabling Reporting Services and SQL Server Agent?

    Introduction
    There is the scenario that users configured hundreds of subscriptions for reports. Now they want to disable all the subscriptions, but Reporting Services and SQL Server Agent service should be enable, so the subscriptions will not delivery reports to users
    and users could run the reports and create jobs on the server.
    Solution
    To achieve this requirement, we need to list all subscriptions and their schedules by running query, then use loop statement to disable all the subscription schedules by Job name.
    On the Start menu, point to All Programs, point to Microsoft SQL Server instance, and then click SQL Server Management Studio.
    Type Server name and select Authentication, click Connect.
    Click New Query in menu to open a new Query Editor window.
    List all subscriptions and their schedules by running the following query:
    Use ReportServer
    go
    SELECT   c.[Name] ReportName,           
    s.ScheduleID JobName,           
    ss.[Description] SubscriptionDescription,           
    ss.DeliveryExtension SubscriptionType,           
    c.[Path] ReportFolderPath,           
    row_number() over(order by s.ScheduleID) as rn             
    into
    #Temp  
    FROM     
    ReportSchedule rs           
    INNER JOIN Schedule s ON rs.ScheduleID = s.ScheduleID           
    INNER JOIN Subscriptions ss ON rs.SubscriptionID = ss.SubscriptionID           
    INNER JOIN [Catalog] c ON rs.ReportID = c.ItemID AND ss.Report_OID = c.ItemID   
    select * from #temp
    Use the loop statement to disable all the subscription schedules by Job name:
    DECLARE
    @count INT,
    @maxCount INT  
    SET @COUNT=1  
    SELECT @maxCount=MAX(RN)
    FROM
    #temp         
    DECLARE
    @job_name VARCHAR(MAX)                  
    WHILE @COUNT <=@maxCount        
    BEGIN      
    SELECT @job_name=jobname FROM #temp WHERE RN=@COUNT  
    exec msdb..sp_update_job @job_name = @job_name,@enabled = 0     
    SET @COUNT=@COUNT+1   P
    RINT @job_name   
    END   
    PRINT @COUNT 
    Reference
    SQL Agent – Disable All Jobs
    Applies to
    Reporting Services 2008
    Reporting Services 2008 R2
    Reporting Services 2012
    Reporting Services 2014
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thanks,
    Is this a supported scenario, or does it use unsupported features?
    For example, can we call exec [ReportServer].dbo.AddEvent @EventType='TimedSubscription', @EventData='b64ce7ec-d598-45cd-bbc2-ea202e0c129d'
    in a supported way?
    Thanks! Josh

  • Java for PI 7.1 EHP1 in Windows and SQL Server 2008

    Hi Gurus
    I try to install PI 7.1 EHP1 in Windows and SQL Server 2008. The questions is :
    What version of java is the correct for this installation???
    And where i can download it??
    Thanks and advance!!!

    Hi Aaron,
    The version for PI 7.1 is 1.5, instead of the 1.4.2 of 7.0/3.0.
    Anyway, for VM settings, you should refer to SAP JVM, which
    is used for the PI 7.11.
    Hope it helps!
    Regards,
    Caio Cagnani

  • JPA and SQL Server 2005's  Identity Don't Play Nice

    I am hoping someone with a little more senior knowledge of JPASQL Server 2005 can point me in the right direction involving SQL Server 2005.
    What I am discovering is JPA and SQL Server 2005 do not playing nice together when you use the IDENTITY capability for
    a primary key. Let me explain. "...when using the IDENTITY as the generator type, the value for the identity field MAY NOT be
    available BEFORE the entity data is saved in the database because typically it is generated when a record is committed."
    My problem is this.
    I have two separate entities using another entity, for example a car has a wheel and a truck has a wheel. I can go through the steps
    of persisting the car and the wheel with no problem. My problem begins when I try to
    find the wheel (by wheel description) for the truck. The query finds the wheel, but does not return the primary key for wheel.
    Therefore, using the PK inside a query generates this error:
    java.lang.IllegalArgumentException: An instance of a null PK has been incorrectly provided for this find operation. What has been my appraoch to get the entity to commit to the database is to use the following sequence for the Entity Manager.
    entityManager.persist(wheel);
    entityManager.flush(); I have assumed to this point this action would persist my data because I have been able to retrieve the PK immidately after these steps.
    However, multiple actions taking place within the same transaction, appears to render the persist and flush steps useless. My initial thought
    is to wrap the wheel creation within a new transaction so when the method/transaction completes, the data would be in the database. This
    has not worked.
    I hope I have explained this clear for others to follow. I apologize in advance if I have not. Any suggestions are greatly appreciated.

    I am hoping someone with a little more senior knowledge of JPASQL Server 2005 can point me in the right direction involving SQL Server 2005.
    What I am discovering is JPA and SQL Server 2005 do not playing nice together when you use the IDENTITY capability for
    a primary key. Let me explain. "...when using the IDENTITY as the generator type, the value for the identity field MAY NOT be
    available BEFORE the entity data is saved in the database because typically it is generated when a record is committed."
    My problem is this.
    I have two separate entities using another entity, for example a car has a wheel and a truck has a wheel. I can go through the steps
    of persisting the car and the wheel with no problem. My problem begins when I try to
    find the wheel (by wheel description) for the truck. The query finds the wheel, but does not return the primary key for wheel.
    Therefore, using the PK inside a query generates this error:
    java.lang.IllegalArgumentException: An instance of a null PK has been incorrectly provided for this find operation. What has been my appraoch to get the entity to commit to the database is to use the following sequence for the Entity Manager.
    entityManager.persist(wheel);
    entityManager.flush(); I have assumed to this point this action would persist my data because I have been able to retrieve the PK immidately after these steps.
    However, multiple actions taking place within the same transaction, appears to render the persist and flush steps useless. My initial thought
    is to wrap the wheel creation within a new transaction so when the method/transaction completes, the data would be in the database. This
    has not worked.
    I hope I have explained this clear for others to follow. I apologize in advance if I have not. Any suggestions are greatly appreciated.

Maybe you are looking for