Wednesday, March 21, 2012

Problem with HOST_NAME Function with Linked View

I have an Access 2000 MDB file with a SQL 7 back end. I have a main table
with 50,000 records; and I have a selections table with 50,000 records for
each machine that uses the database (about 25-50). This allows each user to
have their own set of selections.
The selections table has three fields: ID (int), Sel (bit), MachName
(varchar). ID and MachName comprise the primary key.
I have a view that combines the main table and the entries for the
selections table for the current machine (SQL below). The view works fine
when opened in EM and QA. And if I create a pass-through query from my
Access MDB file, the results are displayed fine.
However, if I link the view to the Access MDB file, I get "#Deleted" in
every field of every record (which seems to indicate that the records were
there and then they were gone). However, if I hard-code the machine name
into the same view instead of using HOST_NAME and then relink the view to
the MDB file, the linked view opens fine. Only when I use HOST_NAME as a
parameter in the view is there a problem with it.
Anyone have any idea what's going on here, or have heard of any issues with
HOST_NAME and ODBC linked objects? SQL for the view is below.
Thanks!
Neil
SELECT INVTRY.*, InvtrySelections.Sel, InvtrySelections.MachName
FROM dbo.INVTRY INNER JOIN
dbo.InvtrySelections ON
dbo.INVTRY.ID = dbo.InvtrySelections.ID
WHERE (dbo.InvtrySelections.MachName = HOST_NAME())Neil wrote:

> I have a view that combines the main table and the entries for the
> selections table for the current machine (SQL below). The view works fine
> when opened in EM and QA. And if I create a pass-through query from my
> Access MDB file, the results are displayed fine.
HOST_NAME() is a T-SQL function. Enterprise Manager, Query Analyzer and
Access Pass-Through querys are direct interfaces to SQL Server and thus
T-SQL

> However, if I link the view to the Access MDB file, I get "#Deleted" in
> every field of every record (which seems to indicate that the records were
> there and then they were gone). However, if I hard-code the machine name
> into the same view instead of using HOST_NAME and then relink the view to
> the MDB file, the linked view opens fine. Only when I use HOST_NAME as a
> parameter in the view is there a problem with it.
Does this not imply that T-SQL cannot construct HOST_NAME() from
Access/Jet SQL?|||First, you shouldn't crosspost to newsgroups not relevant to your problem.
Second, create a view that will simply select and display the value of
HOST_NAME() and you will you see if there is a problem with it and
SQL-Server 7 and a MDB file.
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: http://cerbermail.com/?QugbLEWINF
"Neil" <nospam@.nospam.net> wrote in message
news:lra9f.1731$8c5.1137@.newsread3.news.pas.earthlink.net...
>I have an Access 2000 MDB file with a SQL 7 back end. I have a main table
>with 50,000 records; and I have a selections table with 50,000 records for
>each machine that uses the database (about 25-50). This allows each user to
>have their own set of selections.
> The selections table has three fields: ID (int), Sel (bit), MachName
> (varchar). ID and MachName comprise the primary key.
> I have a view that combines the main table and the entries for the
> selections table for the current machine (SQL below). The view works fine
> when opened in EM and QA. And if I create a pass-through query from my
> Access MDB file, the results are displayed fine.
> However, if I link the view to the Access MDB file, I get "#Deleted" in
> every field of every record (which seems to indicate that the records were
> there and then they were gone). However, if I hard-code the machine name
> into the same view instead of using HOST_NAME and then relink the view to
> the MDB file, the linked view opens fine. Only when I use HOST_NAME as a
> parameter in the view is there a problem with it.
> Anyone have any idea what's going on here, or have heard of any issues
> with HOST_NAME and ODBC linked objects? SQL for the view is below.
> Thanks!
> Neil
> SELECT INVTRY.*, InvtrySelections.Sel, InvtrySelections.MachName
> FROM dbo.INVTRY INNER JOIN
> dbo.InvtrySelections ON
> dbo.INVTRY.ID = dbo.InvtrySelections.ID
> WHERE (dbo.InvtrySelections.MachName = HOST_NAME())
>|||Neil (nospam@.nospam.net) writes:
> SELECT INVTRY.*, InvtrySelections.Sel, InvtrySelections.MachName
> FROM dbo.INVTRY INNER JOIN
> dbo.InvtrySelections ON
> dbo.INVTRY.ID = dbo.InvtrySelections.ID
> WHERE (dbo.InvtrySelections.MachName = HOST_NAME())
Now that I see the entire view, I repeat what I said before: make
MachName nvarchar, and put the clustered index on this column.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Ananda Sim (AnandaSim@.gmail.com.invalid) writes:
> Does this not imply that T-SQL cannot construct HOST_NAME() from
> Access/Jet SQL?
Indeed, the host name must be set through the connection string. I don't
know how it works through Access, but the mechanism is such that the
client tells SQL Server about the name, and lie as much as it want.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Neil wrote:
> I have an Access 2000 MDB file with a SQL 7 back end. I have a main table
> with 50,000 records; and I have a selections table with 50,000 records for
> each machine that uses the database (about 25-50). This allows each user t
o
> have their own set of selections.
> The selections table has three fields: ID (int), Sel (bit), MachName
> (varchar). ID and MachName comprise the primary key.
> I have a view that combines the main table and the entries for the
> selections table for the current machine (SQL below). The view works fine
> when opened in EM and QA. And if I create a pass-through query from my
> Access MDB file, the results are displayed fine.
> However, if I link the view to the Access MDB file, I get "#Deleted" in
> every field of every record (which seems to indicate that the records were
> there and then they were gone). However, if I hard-code the machine name
> into the same view instead of using HOST_NAME and then relink the view to
> the MDB file, the linked view opens fine. Only when I use HOST_NAME as a
> parameter in the view is there a problem with it.
> Anyone have any idea what's going on here, or have heard of any issues wit
h
> HOST_NAME and ODBC linked objects? SQL for the view is below.
I've not had any problems with Host_name() as a parameter, as the only
records I retrieve are for my particular machine there is very little
point in returning that column so I never ask the server for it as I
know the value already.
A couple of things you need to know about Access and SQL Server, firstly
bit fields should be made NOT NULL and default to 0 as Access interprets
these as Jet Yes/No columns and treats them accordingly so it expects a
value to be there (In Access/Jet, a Yes/No column cannot be null and
defaults to 0). The results otherwise can be unpredictable.
Secondly, if you have any floating point columns in your data (including
datetime as these are stored as floating point numbers) then you most
probably need a timestamp column as floating point errors can cause the
#Deleted condition you describe.|||Obscure footnote:
> any floating point columns in your data (including
> datetime as these are stored as floating point numbers)
SQL Server doesn't store datetime as double. Access does,
and the problem arises because of the rounding error in
the conversion between the Access version and the SQL
Server version, even when values are not 'stored' in Access
at all.
(david)
"Trevor Best" <nospam@.localhost.invalid> wrote in message
news:43656dd0$0$345$da0feed9@.news.zen.co.uk...
> Neil wrote:
.>
> I've not had any problems with Host_name() as a parameter, as the only
> records I retrieve are for my particular machine there is very little
> point in returning that column so I never ask the server for it as I
> know the value already.
> A couple of things you need to know about Access and SQL Server, firstly
> bit fields should be made NOT NULL and default to 0 as Access interprets
> these as Jet Yes/No columns and treats them accordingly so it expects a
> value to be there (In Access/Jet, a Yes/No column cannot be null and
> defaults to 0). The results otherwise can be unpredictable.
> Secondly, if you have any floating point columns in your data (including
> datetime as these are stored as floating point numbers) then you most
> probably need a timestamp column as floating point errors can cause the
> #Deleted condition you describe.|||"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:uQV0$Ra3FHA.2432@.TK2MSFTNGP10.phx.gbl...
> First, you shouldn't crosspost to newsgroups not relevant to your problem.
I wasn't aware that I had done that.

> Second, create a view that will simply select and display the value of
> HOST_NAME() and you will you see if there is a problem with it and
> SQL-Server 7 and a MDB file.
Good point. I created a view that returned the value of HOST_NAME(), and it
linked fine into the MDB. I also created a new table, gave it a two-field
PK, and used HOST_NAME() as a parameter for one of the fields in a view.
That view also linked and displayed records fine. (Didn't do a two-table
test, which would be similar to what I'm working with. But it shows that
HOST_NAME() works fine with MDB linked views.)
Neil

> --
> Sylvain Lafontaine, ing.
> MVP - Technologies Virtual-PC
> E-mail: http://cerbermail.com/?QugbLEWINF
>
> "Neil" <nospam@.nospam.net> wrote in message
> news:lra9f.1731$8c5.1137@.newsread3.news.pas.earthlink.net...
>|||After I got your note I did go ahead and make MachName nchar, as BOL says
that HOST_NAME() returns that type, and the sample it showed of storing its
return value in a table used an nchar(30) field.
The InvtrySelections table had the PK (ID/MachName) as the clustered index.
I created a second index on MachName alone, and it made it the clustered
index.
With the above two changes, the results were the same. Still getting
"#Deleted".
Neil
"Erland Sommarskog" <esquel@.sommarskog.se> wrote in message
news:Xns970061F02065Yazorman@.127.0.0.1...
> Neil (nospam@.nospam.net) writes:
> Now that I see the entire view, I repeat what I said before: make
> MachName nvarchar, and put the clustered index on this column.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techin.../2000/books.asp
>|||"Ananda Sim" <AnandaSim@.gmail.com.invalid> wrote in message
news:43653cd2$0$25855$afc38c87@.news.optusnet.com.au...
> Neil wrote:
>
> HOST_NAME() is a T-SQL function. Enterprise Manager, Query Analyzer and
> Access Pass-Through querys are direct interfaces to SQL Server and thus
> T-SQL
>
> Does this not imply that T-SQL cannot construct HOST_NAME() from
> Access/Jet SQL?
In a test, I created a view that returned the HOST_NAME() value, and another
view that used HOST_NAME() as a parameter. Both worked fine when linked to
the MDB file, so the problem's not with T-SQL not being able to construct
HOST_NAME from Jet SQL.
Neil

No comments:

Post a Comment