My SQL Server 2008 R2 database gets deployed from a SSDT project I created. One strange requirement in this case is to change one of the primary key columns to or from IDENTITY depending on where it's deployed. I'm not wild about the requirement but that's not my question.
What I have done is set up a post-deployment script that should run conditionally, depending on where the deployment is occurring. So far, so good.
In my script I am doing an ALTER TABLE ADD command to set up a new column, populate it and rename it to the old column. After this I try to do an UPDATE to the new column and it glitches because the column doesn't exist. I put a GO statement right under the ALTER TABLE ADD command and when I test-run the script in isolation, this solves the problem, everything works great.
-- Add a clone of the ID column with no Identity constraint
ALTER TABLE Communication ADD CommunicationIdNoIdentity INT NOT NULL;
GO
UPDATE Communication
SET CommunicationIdNoIdentity = CommunicationID;
However it appears this is not legal in the context of a post-deployment script. With the GO in place I get a build error right there:
Error: SQL72007: The syntax check failed 'Unexpected end of file occurred.' in the batch near
How can I get around this? The BuildAction on the file is set to "None" which I think is correct.
UPDATE: Although the error is emanating from the child script, I finally got it back to the parent. If I do this:
IF #IsDeploymentToDatacenter = 'TRUE'
:r .\FixIdColumnInCommunicationTable.SQL
it works. If I do this (what I had originally), it fails with the errors I described, among others:
IF #IsDeploymentToDatacenter = 'TRUE'
BEGIN
:r .\FixIdColumnInCommunicationTable.SQL
END
I would be tempted to handle it a different way, you could have the identity in the project but use a deployment contributor to stop it being deployed in the environments you don't need it.
You should be able to use my generic one or write one yourself:
Related
Getting this error, with no table listed, when the user logs in to the order system.
The query is, roughly
SELECT FormParts.*, qrySomeOtherColumns.*, CBool(0) AS ObjMissing INTO Temp_SessionFormParts
FROM FormParts INNER JOIN qrySomeOtherColumns ON FormParts.ID = qrySomeOtherColumns.FormPartID
WHERE EmpId = EmpID();
The data is coming from linked tables with a Postgres back end.
The data is going into the local table "Temp_SessionFormParts"
This is a local table in the front end, so no one else should have access to it.
Everyone else has a copy of the same database, but no one else gets the error.
Where it gets weird is that she only gets the error when she starts the app with our standard shortcut that copies the latest version.
copy "\\NASdiskstation\Install\Deploy\pgFrontEnd.accde" "C:\Merge Documents\"
start "" MSAccess.exe "C:\Merge Documents\pgFrontEnd.accde"
But if she starts Access from the Start Menu, and then opens the same database from the selections, it works fine.
Seems to me that those two routes should give the same result since she's already copied the latest to C:.
I went ahead an posted this question, since I had it written up, because I've seen this error a few times. So this may be helpful.
Normally, you can't SELECT INTO an existing table. But Access detects that situation and helpfully deletes the table before executing the insert.
Somehow this was failing.
DROP TABLE Temp_SessionFormParts
before the INSERT fixed the issue.
No idea why it sometimes didn't work for some people or why running Access directly changed that.
I'm working with a Filemaker script (I'm very inexperienced with Filemaker) and I'm trying to use a double nested loop to accomplish an update on all the portal rows for each record. I'm trying to basically append an 'x' to each portal row's "Desc" field.
It's working except that the inner loop isn't exiting and it just keeps inserting rows into the portal table with 'x' values. When I threw in an early exit I can see the outer loop is working fine. Is "Set Field" supposed to be creating new rows? How can I get this to exit before that happens? I'm aware that I can use "Replace Field Contents" but I'm just teaching myself Filemaker scripting and would like to know why this isn't working. Thanks!
You need to uncheck the option 'Allow creation of records in this table via this relationship' under the details of the relationship on your relationship graph.
With this option checked, any portal created using that relationship has a blank line at the bottom allowing new records to be added. Your 'Set Field' script step is setting that field in the new record line in the portal and therefore creating new records.
Uncheck the option and that blank line disappears and the script will exit.
Your other option, if you want to leave that blank line there, is to amend your script so that it actually works on the related records in their associated table rather than directly on the portal.
Another option would be to use the 'Exit Loop If' script step that tests if a specific field within the portal related record IsEmpty.
I'm sure this is something very simple, but for the life of me can't
find the correct keywords on google.
Basically I've updated a couple models since my last deployment. Dev is set up with the jpa.ddl default setting of create-drop. Now I read that prod isn't supposed to run with jpa.ddl=update, so does that mean I have to manually script a schema change? I couldn't find any documentation saying the correct way. I am also using playapps, so the database is set up there. I set up ssl, so I should have sql access via command line. However, I was having difficulty figuring out the syntax for modifying the db. I'm so used to a gui environment such as phpMySQL or microsoft's sql server. The errors specifically I'm getting are the following two (when running the application after uploading to prod).
Unsuccessful: alter table PhotoSlide add index FK57E3FABF5C905145 (aPhoto_id), add constraint FK57E3FABF5C905145 foreign key (aPhoto_id) references StorePhoto (id)
Cannot add or update a child row: a foreign key constraint fails (play/#sql-2e29_32, CONSTRAINT FK57E3FABF5C905145 FOREIGN KEY (aPhoto_id) REFERENCES StorePhoto (id))
you can achieve that by using the migration module.More details you can find #
http://www.playframework.org/modules/migrate
The flow will be like the below:
You push new code to prod --> you run migrations --> restart the server
More documentation at :
https://github.com/dcardon/play-migrate/blob/master/documentation/manual/home.textile
With the latest version play supports migrations :
http://www.playframework.org/documentation/1.2.4/evolutions
I have a FileMaker script which calculates a value. I have 1 record from table A from which a relation points to n records of table B. What is the best way to set B::Field to this value for each of these n related records?
Doing Set Field [B::Field; $Value] will only set the value of the first of the n related records. What works however is the following:
Go to Related Record [Show only related records; From table: "B"; Using layout: "B_layout" (B)]
Loop
Set Field [B::Field; $Value]
Go To Record/Request/Page [Next; Exit after last]
End Loop
Go to Layout [original layout]
Is there a better way to accomplish this? I dislike the fact that in order to set some value (model) programmatically (controller), I have to create a layout (view) and switch to it, even though the user is not supposed to notice anything like a changing view.
FileMaker always was primarily an end-user tool, so all its scripts are more like macros that repeat user actions. It nowhere near as flexible as programmer-oriented environments. To go to another layout is, actually, a standard method to manipulate related values. You would have to do this anyway if you, say, want to duplicate a related record or print a report.
So:
Your script is quite good, except that you can use the Replace Field Contents script step. Also add Freeze Window script step in the beginning; it will prevent the screen from updating.
If you have a portal to the related table, you may loop over portal rows.
FileMaker plug-in API can execute SQL and there are some plug-ins that expose this functionality. So if you really want, this is also an option.
I myself would prefer the first variant.
Loop through a Portal of Related Records
Looping through a portal that has the related records and setting the field has a couple of advantages over either Replace or Go To Record, Set Field Loop.
You don't have to leave the layout. The portal can be hidden or place off screen if it isn't already on the layout.
You can do it transactionally. IE you can make sure that either all the records get edited or none of them do. This is important since in a multi-user networked solution, records may not always be editable. Neither replace or looping through the records without a portal is transaction safe.
Here is some info on FileMaker transactions.
You can loop through a portal using Go To Portal Row. Like so:
Go To Portal Row [First]
Loop
Set Field [B::Field; $Value]
Go To Portal Row [Next; Exit after last]
End Loop
It depends on what you're using the value for. If you need to hard wire a certain field, then it doesn't sound like you've got a very normalised data structure. The simplest way would be a calculation in TableB instead of a stored field, or if this is something that is stored, could it be a lookup field instead that is set on record creation?
What is the field in TableB being used for and how?
I have a (very simple and standard) UPDATE statement which works fine either directly in Query Analyser, or executed as a stored procedure in Query Analyser.
UPDATE A
SET
A.field1 = B.col1
, A.field2 = B.col2
FROM
tblA AS A INNER JOIN tblB AS B
ON A.pk1 = B.pk1 AND A.pk2 = B.pk2
Problem is when i execute the same stored proc via microsoft ADP (by double-clicking on the sproc name or using the Run option), it says "query ran successfully but did not return records" AND does NOT update the records when i inspect the tables directly.
Before anyone even says "syntax of MS-Access is different than SQLServer T-SQL", remember that with ADP everything happens on the server and one is actually passing thru to T-SQL.
Any bright ideas from any ADP gurus out there?
Gotcha. Responding to my own question for the benefit of anyone else.
Tools / Options / Advanced / Client-Server Settings / Default max records is set at 10,000 (presumably this is the default). Change this to 0 for unlimited.
My table had 100,000+ rows and whatever set of 10,000 it was updating was difficult to find ( among a sea of 90,000+ un-updated rows ). Hence the update did not work fully as expected.
Try and see whether the query gets executed on the SQL Server using SQL profiler.
Also, I think you might need to close the linked table & re-open it to see the updated records.
Does that work?
Run the query with SQL PRofiler running. Before you start the trace add in all the error events. This will give you any errors that the SQL Server is generating that the Access ADP might not be showing correctly (or at all).
Feel free to post them here.
Just as a reference, here's a paper I wrote on Update Queries that discusses some of the issues associated with when the fail.
http://www.fmsinc.com/microsoftaccess/query/snytax/update-query.html
I seem to remember that I always got the "didn't return any rows" message and had to simply turn off the messaging. It's because it isn't returning any rows!
as for the other - sometimes there's a primary key issue. Does the table being updated have a primary key in SQLServer? If so, check the view of the table in Access - sometimes that link doesn't come through. It's been a while, so I could be wrong, but I think you may need to look at the design view of the table while in access and add the primary key there.
EDIT: Additional thought:
in your debugging, try throwing in print statements to see what the values of your inputs are. Is it actually picking up the data from the table as you expect when you execute from access?