Using Access to change SQL tables. Table randomly becomes read-only - sql-server

I have a database that the client needs to update. They like to use access. Some tables randomly become read-only for them. Any ideas why?
They are using Access 2007 and MS SQL 2005.
SQL Table:
CREATE TABLE [dbo].[Users](
[SyncGroup] [varchar](20) NULL,
[UserID] [varchar](20) NOT NULL,
[Password] [varchar](20) NOT NULL,
[Restriction] [text] NULL DEFAULT (' '),
[SiteCode] [varchar](20) NULL,
[Group] [varchar](20) NULL,
[EmpId] [varchar](20) NULL,
[TimeZoneOffset] [int] NULL,
[UseDaylightSavings] [bit] NULL,
PRIMARY KEY ([UserID]) )

Access really likes having a TimeStamp aka RowVersion field on every table. I don't know if this will fix your problem though.
"On servers that support them (such as Microsoft SQL Server), timestamp fields make updating records more efficient. Timestamp fields are maintained by the server and are updated every time the record is updated. If you have a timestamp field, Microsoft Access needs to check only the unique index and the timestamp field to see whether the record has changed since it was last retrieved from the server. Otherwise, Microsoft Access must check all the fields in the record. If you add a timestamp field to an attached table, re-attach the table in order to inform Microsoft Access of the new field."
http://technet.microsoft.com/en-us/library/cc917601.aspx

are users accessing the database while you're trying to do stuff iwth sql? if so, then you will get an error message stating that the database is in use and is read only. no one can be in the database when you are doing things with it though sql.

Sounds like a permissions problem. Are you keeping careful track of who is altering the schema? You may have users who aren't permitted to use changes made by certain other users.

Related

Access requires table relink of SQL Server table every time CurrentDB is opened

I have an Access database that uses SQL Server as its backend. One table is the data for a subform which is loaded into a parent form and displayed in the parent forma as a datasheet. The datasheet is intended to have rows added to it by users.
The subform backend table is defined in SQL Server with a primary key [ID]. The primary key is linked to the Master ID of the current record displayed in the parent form. The subform is then filtered by the relationship between the subform table primary key and the parent form master ID. Nothing unusual here.
The problem that when the parent form is first opened in Access the subform is cannot have records added. It is not until the linked table manager is opened and the backend table is RELINKED can the user add records to the subform. Oddly enough, when relinking the table I am always prompted for the primary key of the table even though it is defined in SQL Server.
The subform has the following settings
Data Entry: Yes
Allow Additions: Yes
Allow Deletions: Yes
Allow Edits: Yes
Allow Filters: Yes
Record Locks: No Locks
Here is the CREATE TABLE for the backend table:
CREATE TABLE [dbo].[ProjectHealth](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Project Health] [nvarchar](2000) NULL,
[Timestamp] [datetime] NULL,
[ProjectID] [int] NULL,
[Entered By] [nvarchar](255) NULL
) ON [PRIMARY]
GO
Again, the RELINK solves the problem. But a VBA TableDef.Refreshlink call does not do the trick. Even if I reset the primary key from VBA.
My suspicion is that I have modified some value in the subform settings that have caused this problem which started happening after a few days of normal behavior. Thanks in advance for any suggestions you can provide.

Remove Summation on Power BI SQL Server Column

How do I remove a summation property for a Power BI SQL table? I have a Customer Transaction Table. For some reason PowerBI is trying to Measure Sum the CustomerTransactionId primary key row. I do not want this added. Please see picture below.
I just want to display all rows in a table.
CREATE TABLE [dbo].[CustomerTransaction]
(
[Customertransactionid] [int] IDENTITY(1,1) primary key NOT NULL,
[Customerid] [int] NULL,
[Quantitybought] [int] NULL,
)
msdn
This is actually done in PowerBI under the modeling ribbon/tab.
When you click on a field (on the right where they are all listed under Fields is fine), the modeling ribbon changes to reflect all settings for that particular field.
Under Default Summarization select 'Do not summarize'.
PowerBI sets Default Summarizations regardless of the data source.

How to retrieve images faster in SQL Server 2014?

We are using SQL Server 2014 (not SQL Azure) and I have defined a simple table to store images (.jpg) and
CREATE TABLE [dbo].[Graphic](
[GraphicID] [int] IDENTITY(1,1) NOT NULL PRIMARY KEY,
[FileName] [varchar](100) NOT NULL,
[FileDescription] [nvarchar](200) NULL,
[Image] [varbinary](max) NULL
)
max size of an image stored is 1MB, this validation is taken care on the front-end. I just inserted 15 images and the table size is 5544 KB currently. There is a primary key placed on GraphicID column. No other indexes placed.
But when I retrieve one or more images using the below (simple SELECT) query, it is taking longer time like 25 - 30 seconds.
select * from [Graphic]
where [GraphicID] = 53
Is there a faster mechanism to query images in SQL Server in less than 5 seconds ?
Is there any alternate SAVE & RETRIEVE mechanism for images in SQL Server 2014 for better performance ?
Please help.
Thanks
Bhanu
CREATE TABLE [dbo].[Graphic](
[GraphicID] [int] IDENTITY(1,1) NOT NULL,
[FileName] [varchar](100) NOT NULL,
[FileDescription] [nvarchar](200) NULL,
[Image] [varbinary](max) NULL
)
If that is indeed your schema (and you seem extremely unsure of it), the problem is that you never added indices to your table. Add a clustered index over GraphicID and it should fix this particular access pattern.
Another note would be that if you know the maximum size of your varbinary (and you said you do), you should use it rather than using max. That way the table layout will store the image inside the row (up to a certain size) rather than appending it at the end, making row retrieval (select *) a lot faster for larger, fragmented tables.

How can I block access for a given index value for the duration of a transaction in SQL Server 2012?

With the table specified below, how could I modify the locking behavior in SQL Server 2012 to block statements and transactions attempting to select data pertaining to a specific UserId column?
I have been attempting to come up with a stored procedure that will successfully change an address for a specific user. In order to do this, the existing record is marked as deleted by setting DeletedOn to the current date. Afterward, the new record is inserted. I do not want any queries to be able to see that no valid address is present for the given user in the table between the deletion mark and the insertion.
Queries related to a different user's address should be able to complete, so long as that user's address is not in the process of being modified.
CREATE TABLE [Address]
(
[Id] BIGINT NOT NULL,
[UserId] FOREIGN KEY REFERENCES [User]([Id]) NOT NULL,
[House] CHARACTER VARYING(255) NOT NULL,
[Street] CHARACTER VARYING(255) NOT NULL,
[City] CHARACTER VARYING (255) NOT NULL,
[State] CHARACTER VARYING(255) NOT NULL,
[Zip] CHARACTER VARYING(15) NOT NULL,
[CreatedOn] DATETIMEOFFSET NOT NULL,
[DeletedOn] DATETIMEOFFSET NULL,
UNIQUE([UserId], [DeletedOn]),
CHECK(([DeletedOn] IS NULL) OR ([CreatedOn] <= [DeletedOn])),
PRIMARY KEY([Id])
);
Using a history table solved this issue. It seems that UNIQUE constraints cause lots of lock escalations when they are defined as composites.
The history table now tracks all of the old versions of a particular record and history inserts are combined with live table updates in a repeatable read transaction.
What do you know, I was approaching the whole problem the wrong way!

SQL Server automatic naming of indexes when creating tables

I'm rather new to SQL Server, (did learn SQL back in late 1980's, DB2 if I recall) Today I'm integrating my database layer into SQL, to begin with, SQL Server.
To begin with. As I do today, I will generate in runtime every databases objects, tables objects and indexes programmatically as I do with almost every visual and data object in my projects. That is, I use the visual designing tools very limited.
Every column in my project has a external description file's (every user has profile which contains these files), just as I do with database key's and for visual objects as for effect's as positioning, length, picture-mask, font size, etc. etc. i.e. dynamic forms. Almost every window, grids, filters is created in runtime just as far most of my database connections.
I did build a small test "machine" to create tables in this environment and did well, very easy to create tables within program (I use delphi and ADO)
The problem I encounter is when I flag a column as "autoincrement" or as Identity in SQL Server or if I describe a column as primary key, then SQL Server Management Studio creates automatically a index or key.
That would be ok if I could manage the name it gives this index or key.
Example of this situations:
AdoCommand.CommandText := Str_SQL;
TRY
AdoCommand.Execute;
FINALLY
NotiFy_TimeOut ('Table was created', wait_for_one_sec);
END;
My database engine creates this SQL script which I pass into the string Str_SQL above:
CREATE TABLE GENGITFL
(
NR INT NOT NULL IDENTITY,
GJM CHAR(3) NOT NULL,
HEITI VARCHAR(25) NOT NULL,
KAUPG REAL NULL,
SOLUG REAL NULL,
TOLLG REAL NULL,
DUMMY VARCHAR(20) NULL,
UNIQUE (GJM),
PRIMARY KEY (GJM)
)
SQL Server creates these two indexes automatically :
PK__GENGITFL__C51F17260A463F49
UQ__GENGITFL__C51F17277FA3E6E6
I don't want to use these names for these files, I would prefer names as:
IDX_GENGITFL_GJM
IDX_GENGITFL_NR
The reason should be obvious in light of my intro, the runtime engine can't create these names automatically and I consider it not a option to look for what index files are available within system database. If my external description say there should be index, I would like just to create names for the index automatically by using the prefix, IDX_ next the table name and last the field name or name's with underscore between, as IDX_GENGITFL_GJM etc.
Hope someone understand my poor english and presentation.. I'm rather rusty in english.
Thanks
Edit: After help from marc_s my SQL "script" is like this:
CREATE TABLE GENGITFL
(
NR INT NOT NULL IDENTITY,
GJM CHAR(3) NOT NULL,
HEITI VARCHAR(25) NOT NULL,
KAUPG REAL NULL,
SOLUG REAL NULL,
TOLLG REAL NULL,
DUMMY VARCHAR(20) NULL,
CONSTRAINT IDX_GENGITFL_NR UNIQUE (NR),
CONSTRAINT IDX_GENGITFL_GJM PRIMARY KEY (GJM),
)
CREATE INDEX IDX_GENGITFL_HEITI ON GENGITFL (HEITI)
Thanks again.
If you don't want the system default names - then just specify your own! :
CREATE TABLE GENGITFL
(
NR INT NOT NULL IDENTITY,
GJM CHAR(3) NOT NULL,
HEITI VARCHAR(25) NOT NULL,
KAUPG REAL NULL,
SOLUG REAL NULL,
TOLLG REAL NULL,
DUMMY VARCHAR(20) NULL,
CONSTRAINT IDX_GENGITFL_NR UNIQUE (GJM),
CONSTRAINT IDX_GENGITFL_GJM PRIMARY KEY (GJM)
)
See those CONSTRAINT (yourownnamehere) before the UNIQUE and the PRIMARY KEY ?
Now, your constraints are named as you defined.

Resources