I have an existing database and I'm trying to connect to it using entity framework, however it throws an exception saying
The server principal "User" is not able to access the database
"DatabaseTwo" under the current security context.
However, I'm not trying to connect to DatabaseTwo, there is no reference to it anywhere in my entire solution.
My DbContext: (DatabaseOne)
Public Class MyContext
Inherits DbContext
Public Sub New()
MyBase.New("DatabaseOne")
End Sub
Public Property Objects As DbSet(Of Object)
End Class
Web.Config connection string:
<add name="DatabaseOne"
connectionString="server=myserver.com;database=DatabaseOne;UID=MyUser;PWD=MyPwd;
APP=MyApp;" providerName="System.Data.SqlClient"/>
The other database does exist on the server and the user does have access to both database one and two, which is also strange consdering it says it dosen't have permission
The Entity had a slightly different name to the table, so using the attribute to specify the exact table name seemed to fix the problem. Still the exception was very strange
<Table("CorrectTableName")>
Public Class MyTable
<Key>
Public Property Id As Integer
End Class
Related
I'm trying to build a .NET Class Library that utilises a SAP generated WSDL.
In the reference.vb file that one of the WSDLs generates, I'm getting the following error in this line:
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified, Order:=0)> _
With the error being BC30369 Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. on System.
This only occurs within one of the generated Partial Public Classes that it generates, and not the rest.
After removing System it works:
'''
<System.Xml.Serialization.XmlElementAttribute(Form:=Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property MESSAGE_V4() As String
Get
Return Me.mESSAGE_V4Field
End Get
Set
Me.mESSAGE_V4Field = Value
End Set
End Property
I have an entity framework model (built using database first) which I have just updated from the database. I now have a whole series of errors in the model, typical of which is;
_Addresses is already declared as Private _Addresses AS System.Data.Objects.ObjectSet(of Address) in this class. If I then double click on the error in the error list it takes me to the following block of codein the Model's designer.vb file.
''' <summary>
''' No Metadata Documentation available.
''' </summary>
Public ReadOnly Property Addresses() As ObjectSet(Of Address)
Get
If (_Addresses Is Nothing) Then
_Addresses = MyBase.CreateObjectSet(Of Address)("Addresses")
End If
Return _Addresses
End Get
End Property
Private _Addresses As ObjectSet(Of Address)
I can see nothing different here to what was there originally, but the project will not build successfully anymore. Can anyone suggest why this may be and what it is that has happened to cause the errors to appear.
More importantly can anyone suggest how one goes about rectifying this without resorting to rebuilding the entity data model from scratch. The data model is in a separate project so it could be rebuilt but it has undergone a lot of customisation so I would prefer not to go down that route.
Thanks for any advice that you can offer.
I'm developing a WCF Data Service to expose a database. I want to provide access to one of the tables (call it 'Foo'), so I put this in the InitializeService method of my DatabaseService.svc.cs:
config.SetEntitySetAccessRule("Foo", EntitySetRights.AllRead);
However, when the service is initialized it throws an ArgumentException with the message "The given name 'Foo' was not found in the entity sets."
The table is definitely in the .edmx file with that name, case and spelling correct. It's also in the .Designer.cs file, like this:
[EdmEntityTypeAttribute(NamespaceName="FooDBModel", Name="Foo")]
[Serializable()]
[DataContractAttribute(IsReference=true)]
public partial class Foo : EntityObject
The service class itself is declared as:
public class FooDatabaseService : DataService<FooDBEntities>
Have you tried using the fully qualified name?
I have a WCF service that returns a class that implements IExtensibleDataObject. I need to add a new field to this class. I updated the DataContract interface and made the change to the class. Now when I try to run my client application I get the following error:
Could not load file or assembly
'xxx.yyyy.zzzz, Version=1.3.9.26111,
Culture=neutral,
PublicKeyToken=b09e2f3e9b5894f0' or
one of its dependencies. The located
assembly's manifest definition does
not match the assembly reference.
(Exception from HRESULT: 0x80131040)
The AssemblyVersion of the WFC class has been changed - does that break client?
EDIT:
There are clients in production that use this service. I do not want to make them update their service reference and redeploy their clients for this simple change if possible.
It depends on how you have set up your data contract.
In WCF, using all the defaults, your service will use the DataContractSerializer (DCS) to serialize your object into XML. The DCS will serialize your fields in order - first the public ones, then the private ones. Within each visibility group, it will order the fields/properties alphabetically by name.
Thus, if you introduce a new public property MiddleName and you already had FirstName and LastName, you would be fine: the old XML would have been
<YourObject>
....
<FirstName>.....</FirstName>
<LastName>.....</LastName>
</YourObject>
and your new one would just simply add a new property at the end:
<YourObject>
....
<FirstName>.....</FirstName>
<LastName>.....</LastName>
<MiddleName>....</MiddleName>
</YourObject>
Such an update "add something at the end" should work just fine, the DCS will just simply ignore additional tags in the XML.
However: had you introduced a property called Gender, that would be stuck between <FirstName> and <LastName> and would thus break the order of the data in your XML and thus would break the data contract - no "old" client will be able to call your new service.
In order to take control of this, you can put specific Order= attributes on your data members in your data contract:
[DataContract]
public class SomeAddress
{
[DataMember(Order=0)]
public string FirstName;
[DataMember(Order=1)]
public string LastName;
}
Then you could easily add a new property - just add it to the end of the list!
[DataContract]
public class SomeAddress
{
[DataMember(Order=0)]
public string FirstName;
[DataMember(Order=1)]
public string LastName;
[DataMember(Order=2)]
public string Gender;
}
So by using the Order= attribute on your data contracts, you can take control of your XML layout, and you can make simple extensions of existing data contracts non-breaking updates.
For more background and in-depth know-how, you ought to read Serialization in Windows Communication Foundation on MSDN Magazine's web site - highly recommended.
From your service reference context menu choose... "Update Service Reference"
Can one client call a public property within a VB.NET module and see the value of that public property changed by another client accessing it at the same time?
Example:
Client 1 calls
Public Module DataModule
Private theDateTime As DateTime = GetAdjustedDateTime() //initial TZ value
Public Property GetSetDateTime() As DateTime
Get
Return theDateTime
End Get
Set(ByVal value As String)
theDateTime = value
End Set
End Property
End Module
by first setting the Property and then getting the value throughout WhateverMethod()...
Partial Class admintours
Inherits System.Web.UI.Page
Private Sub WhateverMethod()
GetSetDateTime = Now
...
...
... //code
...
SomeFunction(GetSetDateTime) //value is 10/14/2010 00:23:56
...
...
//almost simultaneously Client 2 sets the value to Now.AddDays(-1)
...
SomeOtherFunc(GetSetDateTime) //value passed in: 10/13/2010 00:23:56
...
...
... //some more code
...
End Sub
End Class
I'm running into random instances where it looks like another client might be modifying (by setting) the value of GetSetDateTime DURING the first client's run through of WhateverMethod(). This is alarming to me and I've been trying to figure out if that's a possibility. Any confirmation or otherwise as to that would be helpful, thanks!
Modules in VB.Net are shared within an AppDomain. So two clients within the same AppDomain will be operating on the same instance of any given Module. This means one could easily see the results of the other writing to the Module if they are running in parallel in the same AppDomain
In many ways it's best to view the data stored in a Module as global (it's not truly global but behaves that way for many samples).
Yes, if by "client" you mean separate threads in a single application (also assuming a single CPU process and a single AppDomain).
Now, you suggest that it is "alarming" if this is a possibility, so I assume that you want to make sure that this doesn't happen? In order words, you want to ensure that the value of GetSetDateTime remains unchanged during the execution of WhateverMethod.
It sounds like WhateverMethod is only run by "client 1", and the "client 2" code that changes the GetSetDateTime property is independent of WhateverMethod. It doesn't sound like SyncLock would help here.
If both clients are able to change GetSetDateTime at any time then you need to modify WhateverMethod like so:
Private Sub WhateverMethod()
Dim localNow = Now
GetSetDateTime = localNow
...
SomeFunction(localNow)
...
SomeOtherFunc(localNow)
...
End Sub
Does this help?