Insert DateTime into SQL Server 2005 - linq2db

How to configure linq2db to use types for SQL Server 2005? Now I'm trying to do an insert command InsertWithIdentity,
I get the error: "The version of SQL Server in use does not support
datatype 'datetime2'".
For DateTime columns I put attribute [Column ("DataSert", DataType = DataType.DateTime)], does not help.

Try the following connectionString:
<add name="MyName.2005" connectionString="..." providerName="SqlServer" />
or
<add name="MyName" connectionString="..." providerName="SqlServer.2005" />

Related

Store user name and password with neo4j connection string

What is the format (if any) for adding user name and password to neo4j v4 connection strings? So far, I've seen just examples like bolt://localhost:7010 with authentication being added as extra arguments to the connection calls.
Here's why I'm asking:
I have an ASP.NET app which connects to both MS SQL and neo4j DBs. For MS SQL, I can add the connection string to the /configuration/connectionStrings in web.config formatted like this
<add name="MyDB" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MyDB;UID=user;PWD=pwd" />
or
<add name="MyDB" connectionString="Data Source=.,1433;Initial Catalog=MyDB;UID=user;PWD=pwd" />
It contains host name, instance name or port name, plus the credentials. I can then encrypt the connectionStrings part of web.config using standard IIS tools.
For ease of management, I'd like to reuse it for neo4j connection strings as well. I could store the string in MSSQL-like format
<add name="MyNeo4jDB" connectionString="Data Source=.,7010;UID=user;PWD=pwd" />
but I don't want to invent my own format.
Thanks

MVC Controllers - Connection String / associations - No Connection String could be found in the application config file

Please excuse me is this is a noob question. I have a MVC project with a number of EF Database first models. When I created them some were created with new connection strings.
I have tried to clean up the project web.config file and commented out the duplicated connection strings,
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=........... />
<add name="DB_A09819_ProductsEntities" connectionString="metadata=........... />
<add name="DB_A09819_PowerDB001Entities" connectionString="metadata=........... />
<!--
<add name="DB_A09819_ProductsEntities_IntranetDownload" connectionString="metadata........... />
<add name="DB_A09819_ProductsPricing" connectionString="metadata=........... />
<add name="DB_A09819_ProductsProjectProposal" connectionString="metadata=.......... />
<add name="DB_A09819_ProductsProposalSystem" connectionString="metadata=........... />
-->
</connectionStrings>
I had thought that MVC would have picked up on the changes and raised errors, however with these changes the project builds and runs on development server.
When I try to add a controller I now get an error that the
---------------------------
Microsoft Visual Studio
---------------------------
Error
There was an error running the selected code generator:
'Unable to retrieve metadata for 'web...............t'.
No connection string named 'DB_A09819_..........'
could be found in the application config file.'
---------------------------
OK
---------------------------
I would like to change the associations and fix the connection string to have a single connection to each of the databases.
There are a number of posts where the solution is to add a connection string, I am trying to clean up my code and remove duplicate connection strings.
How do I change the association to the connection string in the Model and the controllers to ensure that it will run when deployed ?

How do I setup ASP.NET Identity to use my own connection string?

I have an MVC5 app that's using EF. I would like to add ASP.NET Identity and I've noticed that the connection string for ASP.NET identity is using "DefaultConnection". What Do I need to do so that ASP.NET Identity tables are created in my already existing db (source=DILS-S1301;initial catalog=MVC5;) as specified in MVC5Entities and NOT DefaultConnection => (LocalDb)\v11.0??
thanks
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MySuperAwesomeMVCApp-20131105011429.mdf;Initial Catalog=aspnet-MySuperAwesomeMVCApp-20131105011429;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MVC5Entities" connectionString="metadata=res://*/Models.Mvc5Model.csdl|res://*/Models.Mvc5Model.ssdl|res://*/Models.Mvc5Model.msl;provider=System.Data.SqlClient;provider connection string="data source=DILS-S1301;initial catalog=MVC5;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
I tried modifying "DefaultConnection" like so:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=DILS-S1301;AttachDbFilename=|DataDirectory|\MVC5.mdf;Initial Catalog=MVC5;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MVC5Entities" connectionString="metadata=res://*/Models.Mvc5Model.csdl|res://*/Models.Mvc5Model.ssdl|res://*/Models.Mvc5Model.msl;provider=System.Data.SqlClient;provider connection string="data source=DILS-S1301;initial catalog=MVC5;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
but now i get an error:
Database 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MVC5.mdf' already exists. Choose a different database name.
Cannot attach the file 'C:\Users\blah\Documents\Visual Studio 2013\Projects\MySuperAwesomeMVCApp\MySuperAwesomeMVCApp\App_Data\MVC5.mdf' as database 'MVC5'.
The actual question shall be "How do I setup ASP.NET Identity to use my own connection string?"
If above is the correct summary of your question, below is the answer.
ASP.NET Identity uses EntityFramework for database related tasks. So you can use following option as suitable.
Option 1: EntityFramework's default connection string can be setup using following code snippet in web.config
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Option 2: Programatically, you can also pass ConnectionString name to the DbContext's constructor. like new ApplicationDbContext(MyConnectionString)
Actually all you have to do is change the DefaultConnection connectionString to be your desired connection string. If you used the normal settings for a new MVC 5 project, and the identity tables do not exist in the new DB they will be created there automatically.
You do not have to edit the portion of the connection string and you do not have to edit the DbContext constructor unless you want to change the conntectionString name and are not OK with replacing the default connection string.
If you are OK with replacing the default connection string, you should be able to just replace it... this worked for me.
I found this article helpful as well:
http://www.typecastexception.com/post/2013/10/27/Configuring-Db-Connection-and-Code-First-Migration-for-Identity-Accounts-in-ASPNET-MVC-5-and-Visual-Studio-2013.aspx

connection string in database first mvc project

I have created a database first mvc project that gave me a default connection string in my web.config file.
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\BETADB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Now I need to connect my project to the server database. Connection string:
<add name="name" connectionString="Server=tcp:*******,1433;Database=******;User ID=******;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
When I change the connection string and run I get the following error:
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.
Replace the original connection string you had under 'provider connection string' with the new one from the server:
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot(your connection string here)"" providerName="System.Data.EntityClient" />
Resulting in this connection string:
<add name="name" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:*******,1433;Database=******;User ID=******;Password=******;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=true"" providerName="System.Data.EntityClient" />

Switching from SQL Server Express to SDF database

I've created an mvc project with following connection string (which is a default):
<add name="TestDb"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
I would like to switch from SQL Server Express to one of the file databases, so that I can store my db in same repository. How can I do this (steps/connection string) ?
I'm using MVC code first approach. Thank you.
Install the the EntityFramework.SQLServerCompact NuGet package.
Change your connection string to this:
<add name="TestDb"
providerName="System.Data.SqlServerCe.4.0"
connectionString=
"Data Source=|DataDirectory|\aspnetdb.sdf" />
With Code First, you typically use the context class name as your connection string name.

Resources