I'm developing a cloud service using Azure Mobile Services, and in order to test it quickly and debug it, I want to deploy it in my local computer. I select the project, hit F5, got it running in IIS express in my local PC. I execute the cliente against my local URI address of the IIS service and when I try to insert a value, this exception appears if I try to retrieve or insert a new object:
An exception of type 'System.ArgumentException' occurred in EntityFramework.SqlServer.dll but was not handled in user code
Additional information: The database name 'TR_MyTrip_Server_ExtraData_Service]_Persons_InsertUpdateDelete' is invalid. Database names must be of the form [<schema_name>.]<object_name>.
I debugged the Initialization of the controller and found out that mobile services deploys a LocalDb instance with this connection info on the DataBase property of the ServiceContext object:
Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MyTrip.Server.ExtraData.Service-20140731060708.mdf;Initial Catalog=aspnet-TestProject.Server.ExtraData.Service-20140731060708;Integrated Security=True;MultipleActiveResultSets=True
It is not able to find this DataBase if I try to connect with this connection string to the LocalDB via the SQL Management Studio
I'm able to access to the LocalDb instance with the SQL management studio running this command on CMD and retrieving the Connection for the LocalDB
SqlLocalDB.exe info v11.0
Eitherway, on the SQL Management Studio I'm not able to see any DataBase relating my controller of the Mobile Services. I searched on google and the only related link I found was this but is not working... Does anybody know what's happening?
Thank you so much
This is a problem when you have a project name with periods in it. Like TestProject.Server.ExtraData.Service.
To fix this, go into the web.config and edit the appsetting named "MS_MobileServiceName" taking out the periods. This is the value used as the SQL schema name for your mobile service tables in the database. It can't have periods or other special characters in it.
I generally try to make this the same as the name of the mobile service I'll deploy to, but it's not technically required.
For whatever reason, I couldn't get this working using the accepted answer. I assume this has something to do with the disclaimer in web.config which states:
After publishing to Mobile Services, these settings will be overridden by the values specified in the portal.
However, I did find another work around in the MobileServiceContext file where I replaced this line:
string schema = ServiceSettingsDictionary.GetSchemaName();
if (!string.IsNullOrEmpty(schema))
{
modelBuilder.HasDefaultSchema(schema);
}
with a simple string value modelBuilder.HasDefaultSchema('mySchema');
I imagine there's a way to influence the output of GetSchemaName() but, considering how much effort it took to resolve this problem, I am perfectly content with this solution for now.
If you've changed the MS_MobileServiceName in config to remove the periods, and you're still getting the error, you'll need to re-run the scaffolding for the Initial migration in the package manager console:
Add-Migration Initial -Force
From what I could see, the scaffolding generates an embedded .resx that still has your old schema name (DefaultSchema), and a snapshot (Target) that is referenced in the designer code. Just changing the DefaultSchema didn't solve the issue for me, but re-running the scaffolding did.
I also added Table annotations to my models, but I don't think that was the issue. And probably isn't ideal if your service is already live.
Related
Im learning .net now and following along the course,my goal is to create CRUD app so i need a database to work with it, i have succesfuly created initial migration but database-update doesnot work
(provider: SNI_PN11, error: 50 - Local Database Runtime error
occurred. Cannot create an automatic instance. See the Windows
Application event log for error details.
im getting this error if connection strings look like this
"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
i have installed both sql server and sql management on windows 11 without problem
and if i change connection string to this
"ConnectionStrings": {
"QuotesAppContext": "Server=(localdb)\mssqllocaldb;Database=QuotesAppContext-811c920d-aeb7-4d04-8ba6-5c9a48d8b492;Trusted_Connection=True;MultipleActiveResultSets=true"
}
deleting \ problem now is
Unable to create an object of type 'QuotesAppContext'.
so it seems like an endless circle to me, thanks you for your help
write database-update and get database instance working
I find the answer which have worked for me,find this folder in regedit
"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Microsoft SQL Server\UserInstances"
and delete everything inside of it,and after that run Update-Database command again everything should work fine
P.S
i have tried reinstalling sql server,adding ports, but this solution worked for me
After a few years, I have returned to writing in C# and I am really struggling here - I would like to have my app to have a local SQL database. I have added Service-based database and "Database1.mdf" was added to my project. I created a table and added some data just to see if it is working but I cannot connect to it. I tried numerous connection strings with no success (Server not accessible).
Do I need to run something else in the background? I thought that I might have a local database and with .NET client I can access it, and I hoped it would work whenever I bring my application (also not requiring any SQL server running). Is that wrong?
If you don't require any SQL server, take a look at SQLite. This is lite SQL database engine. Database is just one file. C# has a great library to SQLite on NuGet: https://www.nuget.org/profiles/mistachkin
SQLite is widely used, event in Android (as a native db engine).
here is what i use to connect. it appears as a Data Connection in Server Explorer.
string con2 = #"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Application.StartupPath + "\\jobfile_2017.mdf;Integrated Security=True;Connect Timeout=30";
when i first started working with these, i used this source 1
it works on PC's that i have nothing installed (not even office) but as i said i'd be interested to know of any shortcomings of this method
I experiencing same problem and decided to move mdf file to static c:\db directory. Connection string was changed to incorporate new file location (AttachDbFile).
But AttachDbFile has some issues also (by some reason one table in db is inaccesible and error is access denied).
So I decided to move to Sqlite. LocalDb has many issues to work with. I read good note to resolve problem: in command line stop/remove/start name of instance. But it nuissance.
Wish you good luck to work with these db files.
I had some problems with using the authorization before so I got a brand new everything - new computer, new OS, fresh installation of VS, new app and DB in a new resource group on the Azure. The whole shabang.
I can confirm that I can log in to the Azure DB as the screenshots below show.
I can see the databases, tables, users etc.
The problem is that, although it works locally (using the default connection string provided automagically for me), it doesn't perform very well in the Azure (although I'm using the publish file from there). It said something about the file not being found and according to this answer, I needed to change the connection string.
After I've altered it, I get the following error. Please note that the firewall is open and that I can access the DB when I run the code of my applications. I feel that there's something that goes wrong when the authentication part is automatically configured. I'm out of ideas on how to trouble-shoot it, though.
[SqlException (0x80131904): Login failed for user 'Chamster'.
This session has been assigned a tracing ID of '09121235-87f3-4a92-a371-50bc475306ca'. Provide this tracing ID to customer support when you need assistance.]
The connection string I'm using is this.
Server=tcp:f8goq0bvq7.database.windows.net,1433;
Database=Squicker;
User ID=Chamster#f8goq0bvq7;
Password=Abc123();
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=10;
This issue's bothered me for a while and I'll be bounting it in two days. Any suggestion's warmly appreciated.
I believe I've managed to resolve this weird issue. It appears that the user I'm using, despite being admin with all bells and whistles isn't recognized as admin when used in the connection string and trying to create the tables (which is the case at the first registration).
My solution was to create two logins - one with db_owner role and one with db_datareader and db_datawriter. First, I've used the elevated user in my connection string and registered a single user. That created the tables in the database as shown below.
Then, while able to continue as admin, I realized that we should try the demoted user and tada!, it worked perfectly. Once the tables were there, the whole shabeling behaved as expected.
To be perfectly sure, I dropped the tables from the database and there it was - the same issues as before. When I changed to the elevated user, the tables were restored allowing me to get back to the demoted one.
I also tried dropping the tables, confirming the issues to re-appear and then creating the tables manually. That works too! So basically,the only gotcha that caused it all was the original admin who's not treated as admin.
It might have to do with the fact that my Azure account's getting a bit old, LiveID used there is ancient and that didn't have an updated version of DB in Azure (the pull-up to v12 was carried out the 18th of December, so it's possible that it also was a requirement to get it working). I'm too tired and lazy to check that out and I realize that I've no idea how to get an "old" type of account. Besides, the issue will decrease and gradually vanish because the old accounts get upgraded eventually.
I'm trying to use Entity Framework to add records to a database from a webform input that go into a database on sqlserver.
Everything works fine locally.
I used webmatrix to publish my site to my remote server, the website and my local version of the database is successfully recreated on the remote server with all the data.
However when it comes time to add records to the database, it gives an error on the remote server which i managed to trace to the ctx.Students.Add line.
using (var ctx = new HDPS_SchoolDataEntities())
{
SchoolDataModel.Student temp = new SchoolDataModel.Student();
temp.Name = this.FirstName;
temp.Surname = this.Surname;
temp.Parents = this.Parents;
ctx.Students.Add(temp);
ctx.SaveChanges();
}
I can't find any difference between my local version that works and the one on the remote server that doesn't work. The web.config seems to be configured as expected and all the necessary dll's are in my bin folder but it just won't work on the remote server... any ideas what could be wrong?
Oops forgot the error message!
edit
after Installing .net 4.5 and changing the connection mode from windows authentication to SQL authentication the error now becomes:
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
Everything should be the same on the webserver as the entire website is being copied across but it works fine locally so not sure what the problem is...
OKay I solved the issue with the help of this webpage
http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/
In short It seems webmatrix was does not include the metadata part of the connection string on upload to the server thus the EDMX file containing all the information mapping the classes to the database tables was not being referenced causing any queries to the framework to fail.
Once i pasted the original connection string generated by the Entity Framework wizard onto the server everything worked fine.
Based on the error given in your comment, it sounds like you are failing to connect to the database. Check your connection string, username and password. If those are correct, make sure your database settings allows connections from your server ip address.
OKay I solved the issue with the help of this webpage
http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/
It seems webmatrix was does not include the metadata part of the connection string on upload to the server thus the EDMX file containing all the information mapping the classes to the database tables was not being referenced causing any queries to the framework to fail.
Once i pasted the original connection string generated by the Entity Framework wizard onto the server everything worked fine.
We're writing a multi-tenanted Silverlight application. The user logs in using Windows Forms authentication and we pull the connection string for that user from a table. The string was of the form:
Data Source=1.2.3.4; Initial Catalog=database; Persist Security Info=True; User ID=######; Password=##########
This was working fine. We then decided that setting the application name, for reasons outlined here would be a good idea:
Data Source=1.2.3.4; Initial Catalog=database; Application Name=application; Persist Security Info=True; User ID=######; Password=##########
However, now the connection isn't being made so we're getting errors. This is only failing on the deployed site. Running via Visual Studio is apparently unaffected. There have been no changes to the code that makes the connection. I'm willing to believe that there should be changes, but I haven't been able to work out what they should be.
The connection is being created like this:
public class OurDataContext : DataContext
{
public OurDataContext()
: base(SessionCache.OurConnectionString)
{
....
}
}
SessionCache.OurConnectionString is the string as read from the database.
UPDATE
The change to the connection string may be a red herring. We only get this failure on one web server (the one I don't have direct access to). Adding the property to the database referenced by another web server (that I do have access to) doesn't reproduce the problem. This is leading me to the conclusion that the error is somewhere else. However, I'm still no nearer to solving this.
The actual error is an exception:
An exception of type 'System.ServiceModel.DomainServices.Client.DomainOperationException' occurred and was caught.
------------------------------------------------------------------------------------------------------------------
01/31/2012 14:18:53
Type : System.ServiceModel.DomainServices.Client.DomainOperationException, System.ServiceModel.DomainServices.Client, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Message : Load operation failed for query 'GetUserSecurityConfig'. The remote server returned an error: NotFound.
Status : ServerError
ErrorCode : 0
Data : System.Collections.ListDictionaryInternal
Stack Trace : The stack trace is unavailable.
All the research I've done today on this returns some fairly basic things that shouldn't have changed:
System.ComponentModel.DataAnnotations, System.ServiceModel.DomainServices.EntityFramework, System.ServiceModel.DomainServices.Hosting and System.ServiceModel.DomainServices.Server not being copied to the \bin directory. I've checked and they are.
Errors connecting to the database server. I don't think this is the case as the forms authentication works. It is a different database on the server, but the credentials are the same.
The problem turned out to be due to the version of RIA Services installed on the server.
We'd recently changed the projects to include RIA Services via the NuGet package manager and this server already had RIA Services for VS2010 installed. When we sorted that out everything sprang back to life.
It's not clear why it took so long for this problem to manifest itself though.
We only get this failure on one web server (the one I don't have direct access to). Adding the property to the database referenced by another web server (that I do have access to) doesn't reproduce the problem.
Check webserver config and that the database is installed correctly.
looks like webserver config / db installion to me.