Dynamically Create Always Encrypted Table in SQL Server using c# - sql-server-2016

Is there any way to dynamically create an always encrypted table in C# code, just like we how we create a table dynamically in c# code?

Related

How to pass a local access table as parameter to SQL server?

I am modifying an access 2010 application so that it uses SQL server to run its queries. The data has been transferred to the server some times ago, and used as linked tables, but that proves a bit slow and non-optimal. So I'm trying to put the queries on the server.
I have no problem for simple queries, views,... and I'm using stored functions when there is a need for simple parameters (dates, ids,...).
But now I have a process in that application that selects a bunch of ids in the database, stores them in a local table, does a bunch of actions on them (report with sub report, print preview, print, update of the original records with the date of print when the user confirms that everything printed OK), and empties the local table if all actions succeed.
I can't simply use an SQL server table to store the ids since many people use the application at the same time, and the same table is used in several processes; I can't use temporary tables since they disappear as soon as access goes to the next action; and I can't find a way to use a local table as a parameter to server stored procedures. Basically I'm stuck.
Can anyone help? Is there a way to do that (pass a bunch of values as a table to a server stored function)? Or another process that would achieve the same result (have a table on the server specific to the current user, or a general table and somehow identify the lines belonging to current user, or anything else)?
There are 2 methods that I use. Both work very well for multi-user apps. Here are the basics. You'll need to work out the details.
Create a table (tblSessions) in SQL Server with an identity column SessID (INT NOT NULL).
Create a function in Access to generate and retrieve a new SessID.
Create a second SS table tblWork with 2 columns SessID, YourID. Add appropriate indexes and keys. Link this table to your Access app. Then instead of inserting the IDs for your query into an Access temp table, insert them into tblWork along with a new SessID. You can now join tblWork to other SS tables/views to use as the datasource for you reports. Be sure to add the SessID that you generated to your where clause.
Create a stored procedure to generate the data for your reports. Include a parameter #YourIDList VARCHAR(MAX). Call the proc via a passthrough queryand pass the list of your IDs as a comma (or whatever you prefer) separated string to #YourIDList. In the proc, split #YourIDList into a temp table. SS2016+ has a STRING_SPLIT function. For older versions, roll your own. There are plenty of examples available. Then join the temp table to the other tables you need to generate your output. Use the PT query as your report datasource, or dump it into an Access temp table and use that as you report datasource.

How to insert data using stored procedure after encrypted column using Always Encrypt option?

I am using sql server 2016 and i have encrypted the column using always encryption option. I have connected sql with entity frameworking in ASP.NET MVC application. The dats are inserting properly using insert option. But i cant able to insert using stored procedure via mvc application. I am getting the following error
I have followed the below article.
https://www.codeproject.com/Articles/1110564/WebControls/
How can we refresh the stored procedure to apply encryption?
Error:
"The parameter \"#name\" does not have the same encryption information as the one it was created with. Use sp_refresh_parameter_encryption to refresh the parameter encryption information for the module."
The error message pretty self-explanatory in this case.
Since the encryption metadata has changed since the proc was created, you need to update it via running the sys.sp_refresh_parameter_encryption proc:
exec sys.sp_refresh_parameter_encryption 'SchemaName.ProcedureName'

Convert SQL Insert command to Xamarin SQLite database

I have a lengthy SQL INSERT command that I would essentially like to convert to a local Xamarin database, using SQLite. Is there any easy way around this or do I manually have to create an object from each value which is then entered into the local SQLite database?
If you want to pre-seed your database and ship it with the app, then as Jason suggested, you can use SQLite Manager.
If you want the mobile app to seed the database on first load, you will need to create the objects (tables) first and run the below for each table you have.
SQLiteConnection conn = ....
conn.CreateTable<TableClass>();
Then if you just want to run the insert queries you have, you can use the Execute method.
public int Execute(string query, params object[] args)
However SQLite isn't as powerful as MS SQL and if your insert queries are complex, you will have to modify them and possibly your DB Schema, depending upon column types.

Executing stored procedure using .dbml file LINQ

Using VS 2013 (VB) and SQL Server 2012.
I execute a stored procedure to populate a gridview using linq.
Dim db As New GMConnectionDataContext
Dim gasHedges = db.GasHedges_create2ndMonth.ToList
The stored procedure returns a result set and has been working fine as in it returns the expected result and the gridview displays as desired.
I added some data to my SQL table and loaded the web page and the new data does not show. IF I execute the stored procedure in SQL Server the new data shows. If I execute the stored procedure in VS the new data shows.
Now the weird bit. If I delete the reference to the stored procedure from the .dbml file then re-add it the new data shows when the page is loaded. I know that when using this file if I add columns to a table then I need to delete it and re-add the table to the .dbml file.
Surely the same isn't the case with stored procedures as they would be unusable. Is there something I am missing?
UPDATED
I think I know why this happening but I don't know how to fix it. The SQL result set has dynamic columns as I use the pivot command in SQL. This means that if a user creates a new Gas company the result set will have another column and the datacontext must interpret that as the SP having changed and still shows the old dataset. This does mean I cannot just delete the SP from the datacontext and re-add it as the web application needs to handle if the user adds another company.
Any changes you make in SQL server are not auto-synched to your .dbml file. If you make table or stored procedure changes you need to delete them from the .dbml file and add them again.
Best practices would dictate that you don't pivot your data in SQL. Pivotting data is not a data related issue; it's presentation and should be done in the presentation layer -- in the application.

access: getting create table string

i have a table in access and i would like to get the SQL string from it that will generate the table like:
CREATE TABLE example (
id INT,
data VARCHAR(100)
);
is there any way to do this?
I don't believe there is a built in way. You will have to use a third party tool to convert the schema:
DBWScript
MDBScript
To run a VB Script to convert the tables there is on here:
Table Creation DDL from Microsoft Access
If you are talking about a generic method that will work on any Access table I don't know of any way to get a SQL CREATE table statement directly. I suspect there are too many features in Access (drop down values for fields, input masks, etc.) that don't translate well to SQL.
Access does have the ability to export the table directly to SQL Server however. You could try to push the table to SQL Server and then generate the CREATE statement from that.
If you're trying to port this to SQL server or the like, I think you'll have to build the scripts by hand.
You could always use the SQL server import wizard (or the export to SQL from Access) to move it over, then create the scripts in SQL server.
Don't forget, you can usually get SQL Express for free, so that's a way to do things.
May be exporting the tables to XML/XSD? It's not DDL but you have the schema in a file that you can import using other tools.
More or less as you have it:
CREATE TABLE example (
id INT,
data text(100)
);
You may wish to check out DAO data types: http://allenbrowne.com/ser-49.html