I'm now using SQL Server Compact 3.5 as my local database (in order to make it compatible and running on PCs without SQL Server installed). And I tried to use ADO.NET and Entity Framework to write connection services. However, I found some issues, for example I was trying to save a new object, it looks succeed, but it's actually not really going into the database. I feel it's like just storing in memory or something (when I re-run the project, the data is still there but it's not in the database).
My environment is: SQL Server Compact Edition 3.5 + Visual Studio 2010.
EF code should be correct and is quite simple:
using(TestEntities te = new TestEntities()) {
SystemUser su = new SystemUser();
su.id = 1;
su.name = "123";
te.AddToSystemUsers(su);
te.SaveChanges();
}
I used the same code but with the database in SQL Server Management Tools, it works fine.
Can someone help me explaining with this? Is there any ways to solve the problem?
Big thanks in advance!
You have included the database file as content, and each time you debug, it is copied to the bin/debug folder. To solve this, I recommend using a full path in your connection string.
Related
I am trying to follow quickstart to setup SQL Server (not LocalDb version of SQLServer that comes with Visual Studio) as my data store. Looks like that two databases will be needed - one for configuration and the other for operation. But my problem is that I couldn't figure out what db names I should use. I created two databases using names I came up with and ran the scripts I downloaded from quickstart to create all the tables. Now, when I try to make connection, I think I will need to specify db names in my connection string, don't I? What should I use to replace the original connection string provide by quickstart - "Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.Quickstart.EntityFramework-4.0.0;trusted_connection=yes;" ?
You can have one database for both. But in general I would keep the configuration part in memory if the number of clients is small. Why spend hours keeping the config in a database for just a few clients and resources?
Better to just keep the users and persisted grants in a database.
I am using EF 6.1 and VS 2012 to create a Code First data model basically following the Code First module in Julie Lehrman's EF5 Pluralsight video. It appears to be working just as advertised except I can't find the data file anywhere. I can access it in code, but by no other method.
I am using the LocalDb default connection factory. The database does not appear in the Sql Server Object Explorer under (localdb)v/11.0. There is no mdf file anywhere in the solution or my user folder. Where did Entity Framework put the data?
Maybe looking at the connection string in the debugger will help you find it. Take a look at the Database.Connection.ConnectionString property of the Context you new up.
EF generates a different default connection string depending on the context it's ran in, so I can't tell you for sure where it'll be.
The relevant source code for generating the localdb connection string is here
LocalDb databases have a default location (C:\Users\xxxx\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0), and you can open MSSQL Management Studio against them with the connection string "(localdb)\v11.0" and Windows authentication.
See http://blogs.msdn.com/b/sqlexpress/archive/2011/10/28/localdb-where-is-my-database.aspx
So I've started a SQL Server database project inside VS 2012. I have done this for other databases already but not related to Service Broker.
For testing I had already created db, queues, etc through a T-SQL script including Message Types which was in an XML format. i.e.
[//blah.com/Items/RequestItem]
When I try to do something like this in the DB Project it's not allowing me too due to special chars.
Anyone done this? Gotten around it?
Is there a way to simply put my already created T-SQL file in the database project and have it use it?
See my comment above. I was able to import the script by Right clicking on the database Project.
ASP.NET Membership is just great as there are a ton of functionality right there to be used, and we don't need to change nothing at all.
We can even create our own Provider based on Membership database, and that give us infinite possibilities, like as I don't like the Question/Answer I just use an email that is sent with a reset link.
But this is all done with SQLEXPRESS .mdf file and I wanted to use my own Database for this so I can use SQL Server Enterprise as we have in the Office and not the Express Edition.
How can I easily use the ASP.NET Membership tables in my own Database?
I rememebered some years ago that we needed to use aspnet_reg (something) to create the correct tables, but I can't find that info anymore.
I also tried to use other Membership Providers, namely Altairis.Web.Security from CodePlex and saw the Chris Pels Video on creating a new Membership Provider
On Altairis solution, the Model is not complete and lack several points such as Several Applications as it's made to be used with only one, and Chris Pels contains to much Store Procedures that I need to create by hand.
I'm for given Chris code a go but I just wanted to know if there would be available something easier.
All this is to be integrated in ASP.NET MVC 2 Web Application.
Thanks
You have 3 options:
Do it by running aspnet_regsql.exe: Just open "Start Menu>All Programs>Microsoft Visual Studio 2010>Visual Studio Tools>Visual Studio Command Prompt(2010)" and then type aspnet_regsql. A wizard appears and let you select your desired database.
Do it via API: Use System.Web.Management.SqlServices class and its Install and Uninstall methods. This will programmatically install/uninstall database artifacts.
Do it manually: Go to C:\Windows\Microsoft.NET\Framework\v4.0.30319 or something like. You will find 9 .sql files that begins with Install and 9 .sql files that begins with uninstall. You can run them manually in your database to create needed tables/store procedures/etc. But consider changing database name in sql scripts. Default db name is aspnetdb.
It's aspnet_regsql
Under the following path:
C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regsql
You need to open up the Visual Studio Command Prompt, navigate to C:\WINDOWS\Microsoft.NET\Framework\\aspnet_regsql.exe . Some example are located in the MSDN documentation.
Example: aspnet_regsql.exe -E -S localhost -A mr - installs the database elements for membership and role management on the local computer running SQL Server using Windows authentication.
I've created an app that connects remotely to SQL Server 2008. SQL connections work and all traditional oCommand.ExecuteNonQuery(), work great!
But my SMO class using server.ConnectionContext.ExecuteNonQuery(scriptfile);
ERROR: missing batch parsing.dll .
I can't install these independent utils on a client machines, and then take them all off when done:
as suggested by: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=228de03f-3b5a-428a-923f-58a033d316e1
Since my bulk-inserts are large memory hogs containing complete tables, I wrote the tables to a temptable.sql files and used SQLCMD Util and later switch too SMO and I have the same problem. Neither of these can be leveraged on the client's PCs . Any suggestion? thanks :-)
Well, two things:
if you want to use SMO in your apps, you need to make sure the SMO components are installed on the client machines. You can grab the SMO binaries from Microsoft and you can ship and install them with your app - but that's the only way you'll get those onto the client's computer legally
if you can't do that, how about checking out the SqlBulkCopy class. This is designed specifically for bulk inserting large volumes of data, it's part of ADO.NET 2.0 - no extra installs. There's a whole section in the MSDN library on SQL Server Bulk Operations - check it out!