Showing posts with label sqlserver. Show all posts
Showing posts with label sqlserver. Show all posts

Thursday, March 29, 2012

Create Tables Dynamically

Hi! I am using VS 2003 (v 1.1)

I need to generate tables with the values from the Backend (SQLServer 2000) database in C#.Net.

How can i create the tables, tablerows, cells, etc. from the codebehind page of C#. I am having a very little knowledge about dynamic generation.

Give me the complete code with can example (if possible)

Thanks & Regrads

Jai Shankar

Here's anexample of how to create dynamic controls and add events. You can apply this to any type of control you need (in you case a Table).

Sunday, March 25, 2012

CREATE SYMMETRIC KEY

Hi,
I am in the process of switching an application from SQL Server 2000 to SQL
Server 2005, with the main purpose to use the encryption capabilities of SQL
Server 2005.
To test it out using encryption, I created a database, TestEncrypt, using
all the defaults.
I then worked with the script from the help file in encryption[SQL Serve
r] /
columns / Simple Symmetric Encryption.
When I run
CREATE SYMMETRIC KEY SSN_Key_01
WITH ALGORITHM = AES_256
ENCRYPTION BY CERTIFICATE HumanResources037;
GO
from the script, I get the following error:
Msg 15314, Level 16, State 1, Line 2
Either no algorithm has been specified or the bitlength and the algorithm
specified for the key are not available in this installation of Windows.
When I change this to
CREATE SYMMETRIC KEY SSN_Key_01
WITH ALGORITHM = DES
ENCRYPTION BY CERTIFICATE HumanResources037;
GO
it completes successfully.
However, the Decrypted ID (here is the output):
NationalIDNumber: 002020002
Decrypted ID Number: 2
This does not make sense (the decrypted value should be the same as the
original value).
Full script is below.
Can you tell me why the AES_256 doesn't work (I'm on an XP Pro machine) and
why the decrypted value is different from the original value?
Thanks.
Bob
/* To prevent any potential data loss issues, you should review this script
in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
Use TestEncrypt
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Employee
(
NationalIDNumber varchar(50) NULL
) ON [PRIMARY]
GO
COMMIT
Use TestEncrypt
GO
INSERT INTO dbo.Employee (NationalIDNumber) SELECT '002020002'
GO
SELECT * FROM dbo.Employee
GO
--If there is no master key, create one now
IF NOT EXISTS
(SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)
CREATE MASTER KEY ENCRYPTION BY
PASSWORD =
'23987hxJKL95QYV4369#ghf0%94467GRdkjuw54
ie5y01478dDkjdahflkujaslekjg5k3fd117
r$$#1946kcj$n44ncjhdlj'
GO
CREATE CERTIFICATE HumanResources037
WITH SUBJECT = 'Employee Social Security Numbers';
GO
CREATE SYMMETRIC KEY SSN_Key_01
WITH ALGORITHM = DES
ENCRYPTION BY CERTIFICATE HumanResources037;
GO
USE [TestEncrypt];
GO
-- Create a column in which to store the encrypted data
ALTER TABLE Employee
ADD EncryptedNationalIDNumber varbinary(128);
GO
-- Open the symmetric key with which to encrypt the data
OPEN SYMMETRIC KEY SSN_Key_01
DECRYPTION BY CERTIFICATE HumanResources037;
-- Encrypt the value in column NationalIDNumber with symmetric
-- key SSN_Key_01. Save the result in column EncryptedNationalIDNumber.
UPDATE Employee
SET EncryptedNationalIDNumber = EncryptByKey(Key_GUID('SSN_Key_01'),
NationalIDNumber);
GO
-- Verify the encryption.
-- First, open the symmetric key with which to decrypt the data
OPEN SYMMETRIC KEY SSN_Key_01
DECRYPTION BY CERTIFICATE HumanResources037;
GO
-- Now list the original ID, the encrypted ID, and the
-- decrypted ciphertext. If the decryption worked, the original
-- and the decrypted ID will match.
SELECT NationalIDNumber, EncryptedNationalIDNumber
AS "Encrypted ID Number",
CONVERT(nvarchar, DecryptByKey(EncryptedNationalIDNumber))
AS "Decrypted ID Number"
FROM Employee;
GOI found the problem on the on the encryption inconsistency, still would like
to know about the AES_256. Thanks.
"Gerhard" wrote:

> Hi,
> I am in the process of switching an application from SQL Server 2000 to SQ
L
> Server 2005, with the main purpose to use the encryption capabilities of S
QL
> Server 2005.
> To test it out using encryption, I created a database, TestEncrypt, using
> all the defaults.
> I then worked with the script from the help file in encryption[SQL Ser
ver] /
> columns / Simple Symmetric Encryption.
> When I run
> CREATE SYMMETRIC KEY SSN_Key_01
> WITH ALGORITHM = AES_256
> ENCRYPTION BY CERTIFICATE HumanResources037;
> GO
> from the script, I get the following error:
> Msg 15314, Level 16, State 1, Line 2
> Either no algorithm has been specified or the bitlength and the algorithm
> specified for the key are not available in this installation of Windows.
> When I change this to
> CREATE SYMMETRIC KEY SSN_Key_01
> WITH ALGORITHM = DES
> ENCRYPTION BY CERTIFICATE HumanResources037;
> GO
> it completes successfully.
> However, the Decrypted ID (here is the output):
> NationalIDNumber: 002020002
> Decrypted ID Number: 2
> This does not make sense (the decrypted value should be the same as the
> original value).
> Full script is below.
> Can you tell me why the AES_256 doesn't work (I'm on an XP Pro machine) an
d
> why the decrypted value is different from the original value?
> Thanks.
> Bob
>
> /* To prevent any potential data loss issues, you should review this scrip
t
> in detail before running it outside the context of the database designer.*
/
> BEGIN TRANSACTION
> Use TestEncrypt
> SET QUOTED_IDENTIFIER ON
> SET ARITHABORT ON
> SET NUMERIC_ROUNDABORT OFF
> SET CONCAT_NULL_YIELDS_NULL ON
> SET ANSI_NULLS ON
> SET ANSI_PADDING ON
> SET ANSI_WARNINGS ON
> COMMIT
> BEGIN TRANSACTION
> GO
> CREATE TABLE dbo.Employee
> (
> NationalIDNumber varchar(50) NULL
> ) ON [PRIMARY]
> GO
> COMMIT
> Use TestEncrypt
> GO
> INSERT INTO dbo.Employee (NationalIDNumber) SELECT '002020002'
> GO
> SELECT * FROM dbo.Employee
> GO
> --If there is no master key, create one now
> IF NOT EXISTS
> (SELECT * FROM sys.symmetric_keys WHERE symmetric_key_id = 101)
> CREATE MASTER KEY ENCRYPTION BY
> PASSWORD =
> '23987hxJKL95QYV4369#ghf0%94467GRdkjuw54
ie5y01478dDkjdahflkujaslekjg5k3fd1
17r$$#1946kcj$n44ncjhdlj'
> GO
> CREATE CERTIFICATE HumanResources037
> WITH SUBJECT = 'Employee Social Security Numbers';
> GO
> CREATE SYMMETRIC KEY SSN_Key_01
> WITH ALGORITHM = DES
> ENCRYPTION BY CERTIFICATE HumanResources037;
> GO
> USE [TestEncrypt];
> GO
> -- Create a column in which to store the encrypted data
> ALTER TABLE Employee
> ADD EncryptedNationalIDNumber varbinary(128);
> GO
> -- Open the symmetric key with which to encrypt the data
> OPEN SYMMETRIC KEY SSN_Key_01
> DECRYPTION BY CERTIFICATE HumanResources037;
> -- Encrypt the value in column NationalIDNumber with symmetric
> -- key SSN_Key_01. Save the result in column EncryptedNationalIDNumber.
> UPDATE Employee
> SET EncryptedNationalIDNumber = EncryptByKey(Key_GUID('SSN_Key_01'),
> NationalIDNumber);
> GO
> -- Verify the encryption.
> -- First, open the symmetric key with which to decrypt the data
> OPEN SYMMETRIC KEY SSN_Key_01
> DECRYPTION BY CERTIFICATE HumanResources037;
> GO
> -- Now list the original ID, the encrypted ID, and the
> -- decrypted ciphertext. If the decryption worked, the original
> -- and the decrypted ID will match.
> SELECT NationalIDNumber, EncryptedNationalIDNumber
> AS "Encrypted ID Number",
> CONVERT(nvarchar, DecryptByKey(EncryptedNationalIDNumber))
> AS "Decrypted ID Number"
> FROM Employee;
> GO
>
>
>
>
>|||Depends on the version of Windows you're running. Different versions have
different variations of CryptoAPI. I believe all versions of CryptoAPI have
some basic algorithms available (RC2, DES), but AES is not available on all
platforms.
"Gerhard" <acsla@.community.nospam> wrote in message
news:C771AB35-74D3-40D5-A94C-33C9F08A40FB@.microsoft.com...[vbcol=seagreen]
>I found the problem on the on the encryption inconsistency, still would
>like
> to know about the AES_256. Thanks.
> "Gerhard" wrote:
>|||AES is only supported by SQL Server on Windows 2003.
Laurentiu Cristofor [MSFT]
Software Design Engineer
SQL Server Engine
http://blogs.msdn.com/lcris/
This posting is provided "AS IS" with no warranties, and confers no rights.
"Mike C#" <xyz@.xyz.com> wrote in message
news:uYZddkbhGHA.4892@.TK2MSFTNGP02.phx.gbl...
> Depends on the version of Windows you're running. Different versions have
> different variations of CryptoAPI. I believe all versions of CryptoAPI
> have some basic algorithms available (RC2, DES), but AES is not available
> on all platforms.
> "Gerhard" <acsla@.community.nospam> wrote in message
> news:C771AB35-74D3-40D5-A94C-33C9F08A40FB@.microsoft.com...
>sql

Thursday, March 22, 2012

Create subscription failed.

Hi
I am using merge replication to sync sqlserver 2000 sp3 database and sql
server ce 2.0 sp3 via PPC 2003. I received the following error.
"Sql CE Exception: Create subscription failed:
system.Data.Sqlserverce.sqlceException"
"Create subscription failed (27750 - 8004005)"
Please help.
80004005 is a generic access denied. Are you sure the account you are using
to pull the subscription is in the PAL of your merge publication?
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
"Pcherlop" <Pcherlop@.discussions.microsoft.com> wrote in message
news:930ED762-1874-4513-B675-0FFC27A418E0@.microsoft.com...
> Hi
> I am using merge replication to sync sqlserver 2000 sp3 database and sql
> server ce 2.0 sp3 via PPC 2003. I received the following error.
> "Sql CE Exception: Create subscription failed:
> system.Data.Sqlserverce.sqlceException"
> "Create subscription failed (27750 - 8004005)"
> Please help.

create stored procedures in every new database

Hi. Is there a way to ensure that every database created on a sql
server contains a specific stored procedure? I have a set of stored
procedures that need to exist in every database on the server. Rather
than constantly checking to see if each database has what's necessary,
I was hoping there was a way to setup a template database that would
contains these sp's, and force every new database to use that as a
starting point. Is anything like this possible? Thanks.
On 9 Sep 2004 13:45:10 -0700, Michael Bosco wrote:

>Hi. Is there a way to ensure that every database created on a sql
>server contains a specific stored procedure? I have a set of stored
>procedures that need to exist in every database on the server. Rather
>than constantly checking to see if each database has what's necessary,
>I was hoping there was a way to setup a template database that would
>contains these sp's, and force every new database to use that as a
>starting point. Is anything like this possible? Thanks.
Hi Michael,
Just create the stored procedure(s) in the model database. That is the
template that will be used for all future new databases.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Monday, March 19, 2012

Create related tables from XML schema

I'm new to XML.
I received a schema from one of our vendors (please see below)
I would like to create SQLserver tables required for exporting XML file
later using this schema.
Is there a way to do this in SQLserver?
Thanks
Bill
<CDData> XML Schema
<?xml version="1.0"?>
<!-- CD Schema Basic version 3.2.1 3/2/2004 -->
<!-- SubElements and Attributes for each Element must appear in order
shown -->
<Schema name="CD_Routedata_XML_Schema"
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<ElementType name='PRODUCT' content='eltOnly' model='closed'>
<AttributeType name='PRODNAME' dt:type='string' required='no'/>
<AttributeType name='PRODID' dt:type='string' required='no'/>
<AttributeType name='INVOICE' dt:type='string' required='no'/>
<AttributeType name='QTY' dt:type='number' required='no'/>
<Attribute type='PRODNAME'/>
<Attribute type='PRODID'/>
<Attribute type='INVOICE'/>
<Attribute type='QTY'/>
</ElementType>
<ElementType name='PRODUCTS' content='eltOnly' model='closed'>
<Element type='PRODUCT' minOccurs='0' maxOccurs='*'/>
</ElementType>
<ElementType name='ACCTNAME' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='ACCTID' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='DRIVEDISTTO' content='textOnly' dt:type='number'
model='closed'/>
<ElementType name='DRIVETIMETO' content='textOnly' dt:type='time'
model='closed'/>
<ElementType name='ARRIVE' content='textOnly' dt:type='datetime'
model='closed'/>
<ElementType name='DURATION' content='textOnly' dt:type='time'
model='closed'/>
<ElementType name='DEPART' content='textOnly' dt:type='datetime'
model='closed'/>
<ElementType name='CODE' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='STOP' content='eltOnly' model='closed'>
<AttributeType name='NUM' dt:type='ui2' required='yes'/>
<Attribute type='NUM'/>
<Element type='ACCTNAME' minOccurs='0' maxOccurs='1'/>
<Element type='ACCTID' minOccurs='1' maxOccurs='1'/>
<Element type='DRIVEDISTTO' minOccurs='0' maxOccurs='1'/>
<Element type='DRIVETIMETO' minOccurs='0' maxOccurs='1'/>
<Element type='ARRIVE' minOccurs='0' maxOccurs='1'/>
<Element type='DURATION' minOccurs='0' maxOccurs='1'/>
<Element type='DEPART' minOccurs='0' maxOccurs='1'/>
<Element type='CODE' minOccurs='0' maxOccurs='1'/>
<Element type='PRODUCTS' minOccurs='0' maxOccurs='1'/>
</ElementType>
<ElementType name='DRIVERID' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='CODRIVERID' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='TRAILER1ID' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='TRAILER2ID' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='TRAILER3ID' content='textOnly' dt:type='string'
model='closed'/>
<ElementType name='ROUTE' content='eltOnly' model='closed'>
<AttributeType name='DATE' dt:type='datetime' required='yes'/>
<AttributeType name='SITEID' dt:type='string' required='yes'/>
<AttributeType name='ROUTEID' dt:type='string' required='yes'/>
<Attribute type='DATE'/>
<Attribute type='ROUTEID'/>
<Attribute type='SITEID'/>
<Element type='DRIVERID' minOccurs='0' maxOccurs='1'/>
<Element type='CODRIVERID' minOccurs='0' maxOccurs='1'/>
<Element type='TRAILER1ID' minOccurs='0' maxOccurs='1'/>
<Element type='TRAILER2ID' minOccurs='0' maxOccurs='1'/>
<Element type='TRAILER3ID' minOccurs='0' maxOccurs='1'/>
<Element type='STOP' minOccurs='1' maxOccurs='*'/>
</ElementType>
<ElementType name='MOBIUSROUTES' content='eltOnly' model='closed'>
<AttributeType name='ADD' dt:type='string' required='no'/>
<Attribute type='ADD'/>
<Element type='ROUTE' minOccurs='1' maxOccurs='*'/>
</ElementType>
<ElementType name='CADECDATA' content='eltOnly' model='closed'>
<Element type='MOBIUSROUTES' minOccurs='0' maxOccurs='1'/>
</ElementType>
<ElementType name='BASE' content='eltOnly' model='open'>
<Element type='CADECDATA' minOccurs='0' maxOccurs='1'/>
</ElementType>
</Schema>
Look at the SchemaGen option of the SQLXML XML Bulkload object.
Best regards
Michael
"Bill Nguyen" <billn_nospam_please@.jaco.com> wrote in message
news:eCA47z88GHA.3280@.TK2MSFTNGP02.phx.gbl...
> I'm new to XML.
> I received a schema from one of our vendors (please see below)
> I would like to create SQLserver tables required for exporting XML file
> later using this schema.
> Is there a way to do this in SQLserver?
> Thanks
> Bill
> --
> <CDData> XML Schema
> <?xml version="1.0"?>
> <!-- CD Schema Basic version 3.2.1 3/2/2004 -->
> <!-- SubElements and Attributes for each Element must appear in order
> shown -->
> <Schema name="CD_Routedata_XML_Schema"
> xmlns="urn:schemas-microsoft-com:xml-data"
> xmlns:dt="urn:schemas-microsoft-com:datatypes">
> <ElementType name='PRODUCT' content='eltOnly' model='closed'>
> <AttributeType name='PRODNAME' dt:type='string' required='no'/>
> <AttributeType name='PRODID' dt:type='string' required='no'/>
> <AttributeType name='INVOICE' dt:type='string' required='no'/>
> <AttributeType name='QTY' dt:type='number' required='no'/>
> <Attribute type='PRODNAME'/>
> <Attribute type='PRODID'/>
> <Attribute type='INVOICE'/>
> <Attribute type='QTY'/>
> </ElementType>
> <ElementType name='PRODUCTS' content='eltOnly' model='closed'>
> <Element type='PRODUCT' minOccurs='0' maxOccurs='*'/>
> </ElementType>
> <ElementType name='ACCTNAME' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='ACCTID' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='DRIVEDISTTO' content='textOnly' dt:type='number'
> model='closed'/>
> <ElementType name='DRIVETIMETO' content='textOnly' dt:type='time'
> model='closed'/>
> <ElementType name='ARRIVE' content='textOnly' dt:type='datetime'
> model='closed'/>
> <ElementType name='DURATION' content='textOnly' dt:type='time'
> model='closed'/>
> <ElementType name='DEPART' content='textOnly' dt:type='datetime'
> model='closed'/>
> <ElementType name='CODE' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='STOP' content='eltOnly' model='closed'>
> <AttributeType name='NUM' dt:type='ui2' required='yes'/>
> <Attribute type='NUM'/>
> <Element type='ACCTNAME' minOccurs='0' maxOccurs='1'/>
> <Element type='ACCTID' minOccurs='1' maxOccurs='1'/>
> <Element type='DRIVEDISTTO' minOccurs='0' maxOccurs='1'/>
> <Element type='DRIVETIMETO' minOccurs='0' maxOccurs='1'/>
> <Element type='ARRIVE' minOccurs='0' maxOccurs='1'/>
> <Element type='DURATION' minOccurs='0' maxOccurs='1'/>
> <Element type='DEPART' minOccurs='0' maxOccurs='1'/>
> <Element type='CODE' minOccurs='0' maxOccurs='1'/>
> <Element type='PRODUCTS' minOccurs='0' maxOccurs='1'/>
> </ElementType>
> <ElementType name='DRIVERID' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='CODRIVERID' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='TRAILER1ID' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='TRAILER2ID' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='TRAILER3ID' content='textOnly' dt:type='string'
> model='closed'/>
> <ElementType name='ROUTE' content='eltOnly' model='closed'>
> <AttributeType name='DATE' dt:type='datetime' required='yes'/>
> <AttributeType name='SITEID' dt:type='string' required='yes'/>
> <AttributeType name='ROUTEID' dt:type='string' required='yes'/>
> <Attribute type='DATE'/>
> <Attribute type='ROUTEID'/>
> <Attribute type='SITEID'/>
> <Element type='DRIVERID' minOccurs='0' maxOccurs='1'/>
> <Element type='CODRIVERID' minOccurs='0' maxOccurs='1'/>
> <Element type='TRAILER1ID' minOccurs='0' maxOccurs='1'/>
> <Element type='TRAILER2ID' minOccurs='0' maxOccurs='1'/>
> <Element type='TRAILER3ID' minOccurs='0' maxOccurs='1'/>
> <Element type='STOP' minOccurs='1' maxOccurs='*'/>
> </ElementType>
> <ElementType name='MOBIUSROUTES' content='eltOnly' model='closed'>
> <AttributeType name='ADD' dt:type='string' required='no'/>
> <Attribute type='ADD'/>
> <Element type='ROUTE' minOccurs='1' maxOccurs='*'/>
> </ElementType>
> <ElementType name='CADECDATA' content='eltOnly' model='closed'>
> <Element type='MOBIUSROUTES' minOccurs='0' maxOccurs='1'/>
> </ElementType>
> <ElementType name='BASE' content='eltOnly' model='open'>
> <Element type='CADECDATA' minOccurs='0' maxOccurs='1'/>
> </ElementType>
> </Schema>
>

Create project/stored procedure for SQLCRL

I installed SQLServer 2005 Standard Edition and tried to created a
stored procedure in VB. From START/PROGRAMS/MICROSOFT VISUAL STUDIO
2005, I created a blank solution. What type of project shall I create
for creating a stored procedure in VB ?

I tried to install SQL Server again in case I left back some parts, but
I got a message that all parts were installed.On 7 Jun 2006 00:37:56 -0700, Chris wrote:

>I installed SQLServer 2005 Standard Edition and tried to created a
>stored procedure in VB. From START/PROGRAMS/MICROSOFT VISUAL STUDIO
>2005, I created a blank solution. What type of project shall I create
>for creating a stored procedure in VB ?
>I tried to install SQL Server again in case I left back some parts, but
>I got a message that all parts were installed.

Hi Chris,

Create a "database" project, using the "SQL Server Project" template.
After that, you can choose the "Project" / "Add Stored Procedure" menu
choice to add a CLR stored procedure to your project.

--
Hugo Kornelis, SQL Server MVP|||Thanks a lot, Hugo.