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
Related
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'm currently using VS2015 and a local instance of MySQL Server (managed through Workbench) to develop a school project.
The project is a Web form app (.NET/C#) which I have never really done before. I have done C# with a MySQL connection in the past but I think it was just a Windows form app, and I had no issues connecting the database to the form.
I'm currently trying to use a GridView element from the toolbox in Visual Studio to connect to my database. When I go in and edit the source settings, I can create a connection and it will see the tables in my database.
I can then click the "Test Connection" button and it will succeed in connecting. However, if I go forward and try to select items to view from the table, and then click "Test Query" I get the following error:
I have Googled the error and tried some of the solutions found on SO like installing the Clear MEF Cache extension, but it didn't solve anything.
Additionally, I've created some functions from scratch to connect and insert data. They also have problems in that trying to insert any more than one value into the table will fail. Like INSERT INTO user_info(user_id, user_name) VALUES ('5', "Bob") will insert the user_id but not the user_name.
Please see here for a tutorial to connect to MySQL and here for filling your DataGridView from MySQL. Make sure you have the correct reference added to your project as well (References > MySQL.Data).
I'm currently working with VS'13 for making c# metro forms and mysql workbench for database. The problem occurring is that it shows the error of
Missing Server and User in Credentials.
Host 'WAJiHA' is not allowed to connect to this MySQL server
(as you can see in the picture as well).
DataAccess file has following settings
"Server=localhost;Database=sbhd_v13;Uid=root;password=test123";
The database is connected with the project and executes query but doesnot allows to access the connection to the current project or any other project.
It was working good last night idk which configurations i had edited by mistake which is causing such error.
Kindly help me! I'm unable to find the right solution for this problementer image description here
Change your posted connection string to be like
string myConnectionString = "server=127.0.0.1;uid=root;pwd=test123;database=sbhd_v13;";
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.
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.