I have created a module which have 3 fields(textbox) .Now I want to insert all these fields in Database table. So my question how to create table , how to make a connection and how to code related to insert, update ,delete and select data form that table in DNN 6.0
You may create table as your module installing. In the sql script file (01.00.00.SqlDataProvider), you can write sql scripts (like create table, create procedure, ...).
Also for your insert/update/delete/... you can use linq or a controller which calls stored-procedures.
Check this link for more details.
Related
I have a Database project for my personal project and I am trying to deploy my code to my DEV server. I frequently delete and re-create my DEV Server. Right now, DEV Server is newly created with SQL Server. Every time I want to deploy my code I have to manually create Database Project and then publish database project. I want to automate creation of Database with database project deployment.
Right now, I have a script that creates database, but I have to execute it manually. And this is working perfectly but I want to automate this step as well.
Is this even possible? If yes, then how? Please explain step by step. Also what will we mention for Initial Catalog in connection string?
Edit:
I tried to create Database by using
CREATE DATABASE LocalDbTest
in Pre-Deployment Script. But it didn't work. It is creating Database, but then tables are not getting created tables under it. Since I used master database as default database, it is creating table under master. It is not letting me select LocalDbTest database as default because it is not yet created, so I have to select Master as my default database. I tried to Change Database by:
USE LocalDbTest
GO
I used it just after creating Database but this didn't work because when generating script it is changing back to default database. This part is coming automatically when generating script.
USE [$(DatabaseName)];
GO
Also Visual Studio is not letting me add database name in front of table name like:
CREATE TABLE [LocalDbTest].[dbo].[TestTable]
I am getting error:
When you create an object of this type in a database project, the object's name must contain no more than two parts.
If you have a script ready for database creation, you can use the Pre-build event to call SQLCMD and run your script.
Edit:
If you have trouble pointing to a database that does not exist, you may have to manually edit the publish profile (ex. dev.publish.xml) and set the TargetDatabaseName element explicitly. You can also set CreateNewDatabase element to True if you want to be recreated every time it gets published.
Answer:
You can use a publish profile and hardcode the target database in it.
I created a table using the create table command but it does not show up in the object explorer. I have tried refreshing both the explorer and IntelliSense but it still does not show up. The table is present in the database I confirmed that by printing it out using the select command.
It appears like you created your table in the system master database instead of in your user defined database. There are a few things you can do:
At the top of your query, write USE your_database_name That will set your connection to run your query against a specific database.
In SSMS, on the top left by default I think, there should be a white box with a dropdown arrow next to it. This is a list of all the databases in the instance you are currently connected to. Click yours, and run your table create.
Fully qualify your table name during the create as my_database_name.schema_here.table_name_here
Always look at the bottom of your SSMS window and confirm you are running queries in the correct instance (dev vs prod) and running them against the correct database.
USE database_name
GO
CREATE TABLE dbo.my_new_table (ID INT)
GO
or
CREATE TABLE database1.dbo.test_user_table (ID INT)
GO
I'm using IntelliJ to create my application, and an Oracle Database.
At the moment, I have to migrate data from an older database SCHEMA to a newer one. Tables and columns changed, and I want to create a IQBase script, which will be run on the different server during installation of the new application version.
So I have got, data in the old SCHEMA (we will talk about OLD_SCHEMA) and I want to SELECT these data, transform them and INSERT INTO the NEW_SCHEMA. So I wanna do something like :
INSERT INTO NEW_SCHEMA.TABLE_X (........) SET (SELECT ..... FROM OLD_SCHEMA.TABLE_Y)
BUT When I'm trying to executing this kind of query in the database tool bundled with IntelliJ, I got an error explaining, that there is a non existing table or a view.
[2016-09-06 15:22:29] [42000][942] ORA-00942: Table ou vue inexistante
It seems normal, because, when I create a SQL console file to test my queries, it is linked to one of the two schema.
So, can I , and if I can, How to execute my queries to use data of the two schema ?
Thank you.
PS : An Import, export isn't the solution, the structure changed a lot.
To work with two schemas your USER must have grants (on SELECT, INSERT, etc.) in both schemas.
Also you use wrong sintax for INSERT statement, you need use sintax like this
INSERT INTO NEW_SCHEMA.TABLE_X (........) SELECT ..... FROM OLD_SCHEMA.TABLE_Y
You cannot query tables in another schema, unless you have been given the right to do so. If you connect to new_schema and want to query old_schema.table_y you need select privileges on old_schema.table_y.
In order to do so connect to old_schema and grant these privileges.
grant select on table_y to new_schema;
Now your query should work (without the set statement).
See this link for a syntax example.
Oracle insert from select into table with more columns
I'm trying to create a database project from an extant database. Some of the tables in the database have CDC enabled. For each such table, we've created a view into the CDC data that looks something like:
create view [dbo].[vw_cdc_myTable] as
select
sys.fn_cdc_map_lsn_to_time (__$start_lsn) ActionLocalTime
, __$seqval ActionOrder
, __$operation ImageType
, case __$operation
when 1 then 'Deleted'
when 2 then 'Inserted'
when 3 then 'Before Update'
when 4 then 'After Update'
end ImageType_desc
, convert(char(5), '>>>>>') Sprtr
, *
from
cdc.dbo_myTable_CT
SSDT complains about this as it didn't import any of the CDC objects (in this case, cdc.dbo_myTable_CT and sys.fn_cdc_map_lsn_to_time). Is there any way to either have those imported or to fake SSDT out so that I can have the view in source control?
Yes, there's a way to do it. It's called cheating, but it works wonders.
Follow these steps:
Create a stub SSDT project in your solution and call it CDC (or whatever placeholder name you want)
Add a schema object to that fake project, named [cdc]
Script out the CREATE of your dbo_myTable_CT and add it as a table object to your fake project
Now the fun begins: Add that fake a project as a database reference to your main project, and name the SQLCMD variable for the reference as CDC (for example)
Change the from clause in your view to look like this:
from [$(CDC)].cdc.dbo_myTable_CT
Now, when you are deploying your database, when asked for the actual name for the CDC database, just use the same database name in your own project. They are the same database, technically. You main code will be deployed, while the cdc table in the target won't be touched.
That's it!
You can also use this trick to make deployment ignore publishing of certain objects altogether while still husing them in some way.
I've got a project where I'm attempting to use SQLite via System.Data.SQLite. In my attempts to keep the database under version-control, I went ahead and created a Database Project in my VS2008. Sounds fine, right?
I created my first table create script and tried to run it using right-click->Run on the script and I get this error message:
This operation is not supported for the provider or data source you are using.
Does anyone know if there's an automatic way to use scripts that are part of database project against SQLite databases referenced by the databases, using the provider supplied by the System.Data.SQLite install?
I've tried every variation I can think of in an attempt to get the script to run using the default Run or Run On... commands. Here's the script in it's most verbose and probably incorrect form:
USE Characters
GO
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'Skills')
BEGIN
DROP Table Skills
END
GO
CREATE TABLE Skills
(
SkillID INTEGER PRIMARY KEY AUTOINCREMENT,
SkillName TEXT,
Description TEXT
)
GO
Please note, this is my first attempt at using a Database, and also the first time I've ever touched SQLite. In my attempts to get it to run, I've stripped any and everything out except for the CREATE TABLE command.
UPDATE: Ok, so as Robert Harvey points out below, this looks like an SQL Server stored procedure. I went into the Server Explorer and used my connection (from the Database project) to get do what he suggested regarding creating a table. I can generate SQL from to create the table and it comes out like thus:
CREATE TABLE [Skills] (
[SkillID] integer PRIMARY KEY NOT NULL,
[SkillName] text NOT NULL,
[Description] text NOT NULL
);
I can easily copy this and add it to the project (or add it to another project that handles the rest of my data-access), but is there anyway to automate this on build? I suppose, since SQLite is a single-file in this case that I could also keep the built database under version-control as well.
Thoughts? Best practices for this instance?
UPDATE: I'm thinking that, since I plan on using Fluent NHibernate, I may just use it's auto-persistence model to keep my database up-to-snuff and effectively in source control. Thoughts? Pitfalls? I think I'll have to keep initial population inserts in source-control separately, but it should work.
I built my database using an SQLite SQL script and then fed that into the sqlite3.exe console program like this.
c:\sqlite3.exe mydatabase.db < FileContainingSQLiteSQLCommands
John
Well, your script looks like a SQL Server stored procedure. SQLite most likely doesn't support this, because
It doesn't support stored procedures, and
It doesn't understand SQL Server T-SQL
SQL is actually a pseudo-standard. It differs between vendors and sometimes even between different versions of a product within the same vendor.
That said, I don't see any reason why you can't run any (SQLite compatible) SQL statement against the SQLite database by opening up connection and command objects, just like you would with SQL Server.
Since, however, you are new to databases and SQLite, here is how you should start. I assume you already have SQLite installed
Create a new Windows Application in Visual Studio 2008. The database application will be of no use to you.
Open the Server Explorer by pulling down the View menu and selecting Server Explorer.
Create a new connection by right-clicking on the Data Connections node in Server Explorer and clicking on Add New Connection...
Click the Change button
Select the SQLite provider
Give your database a file name.
Click OK.
A new Data Connection should appear in the Server Explorer. You can create your first table by right-clicking on the Tables node and selecting Add New Table.