Showing posts with label customer. Show all posts
Showing posts with label customer. Show all posts

Sunday, March 25, 2012

Create table as I need it, how to reference in query?

I'll try to use the customer/orders example for my situation.
Let's say I have 10 customers and each customer has n order records. Most
of the time I will just accept the default order of the order records. In
other words, when I SELECT a customers orders I get them back in the order
they are in the table.
In some cases (remember, I'm not really dealing with customers/orders) I
want to explicitly re-order a customer's order records. Not by any
particular field. There is no logical pattern.
I was thinking that I could maintain a Customer_Orders_Order table. It
would look something like this:
[ CustomerID (FK to the customer tbl) ] [ OrderIndex ] [ OrderID (FK to
Order tbl) ]
the values might look like:
1 1 2
1 2 5
1 3 8
1 4 9
2 1 2
2 2 4
2 3 3
2 4 1
2 5 5
I would use this table to display the orders in the desired order in the UI.
OrderIndex would be the index in a ListView or DataGrid, etc.
My question is, would you store all the information in a single table or
would you create a table per customer to store this information and only if
the Customer's orders have actually been reordered from their default
presentation order (row order in the table)?
If your answer is create a table for each customer, how do you work with a
dynamically created table in a sproc or query? If my client app detects
that a user dragged an order above another order thus changing the
presentation order, I would create a table with a unique name, maybe
Tbl<customerName>_OrderPresentationOrdering. Then I could insert the
ordering information. Now, later when I want to display this customer's
orders and want to check if there is explicit presentation ordering that I
should use, how do I query the table I just created? Assuming I know the
naming convention used, can you concatenate a string in a sproc to build a
table name to be used in a Query?
Man, I hope this makes sense to someone, it's hard to explain.. :)
Thanks for any help,
SteveI was just thinking about this and realized that updates and inserts would
be involved due to the quantity of item in the update/insert. This got me
thinking... If I store this data per customer, inside the customer record,
then I don't need to have anything other than an array of OrderIDs.
So I can just have a delimited string stored in a field called
"OrderOrdering" (stupid name, my actual name would be "ProtocolOrdering" but
sticking with the example....)
something like:
4;2;7;1;3;5
Insert and updates are easy (fast) and there really is no need to normalize
data like this, is there? I won't use it for searches or anything.
If anyone has a compelling reason why I shouldn't do this, please share,
please, please.
"Steve" <sss@.sss.com> wrote in message
news:uThe317QGHA.6084@.TK2MSFTNGP10.phx.gbl...
> I'll try to use the customer/orders example for my situation.
> Let's say I have 10 customers and each customer has n order records. Most
> of the time I will just accept the default order of the order records. In
> other words, when I SELECT a customers orders I get them back in the order
> they are in the table.
> In some cases (remember, I'm not really dealing with customers/orders) I
> want to explicitly re-order a customer's order records. Not by any
> particular field. There is no logical pattern.
> I was thinking that I could maintain a Customer_Orders_Order table. It
> would look something like this:
> [ CustomerID (FK to the customer tbl) ] [ OrderIndex ] [ OrderID (FK
> to Order tbl) ]
>
> the values might look like:
> 1 1 2
> 1 2 5
> 1 3 8
> 1 4 9
> 2 1 2
> 2 2 4
> 2 3 3
> 2 4 1
> 2 5 5
> I would use this table to display the orders in the desired order in the
> UI. OrderIndex would be the index in a ListView or DataGrid, etc.
> My question is, would you store all the information in a single table or
> would you create a table per customer to store this information and only
> if the Customer's orders have actually been reordered from their default
> presentation order (row order in the table)?
> If your answer is create a table for each customer, how do you work with a
> dynamically created table in a sproc or query? If my client app detects
> that a user dragged an order above another order thus changing the
> presentation order, I would create a table with a unique name, maybe
> Tbl<customerName>_OrderPresentationOrdering. Then I could insert the
> ordering information. Now, later when I want to display this customer's
> orders and want to check if there is explicit presentation ordering that I
> should use, how do I query the table I just created? Assuming I know the
> naming convention used, can you concatenate a string in a sproc to build a
> table name to be used in a Query?
> Man, I hope this makes sense to someone, it's hard to explain.. :)
> Thanks for any help,
> Steve
>|||I have a feeling you're about to feel the wrath of JC.
But to answer your question, you would create a single table for this.
I see what you mean by your sorting information. In that case, I
consider that type of data to not have anything to do with the database
-- while it's human readable and client readable, I consider the data
to be arbitrary to anything accessing it within the database. It might
as well be random binary data for all your database is concerned. Now,
the question is, does this data belong in your database? You're
breaking encapsulation by storing this in your database if it's not
specific to the data. I make two exceptions to putting
application-specific data within a database. The first is when the
database is used by one and only one application, and will be used by
one and only one application for the purpose of storing data and logic
specific to that application. The second is when the performance or
implementation advantages of storing such application-specific logic
and data are exceptionally significant.
-Alan|||Steve wrote:
> I was just thinking about this and realized that updates and inserts would
> be involved due to the quantity of item in the update/insert. This got me
> thinking... If I store this data per customer, inside the customer record
,
> then I don't need to have anything other than an array of OrderIDs.
> So I can just have a delimited string stored in a field called
> "OrderOrdering" (stupid name, my actual name would be "ProtocolOrdering" b
ut
> sticking with the example....)
> something like:
> 4;2;7;1;3;5
> Insert and updates are easy (fast) and there really is no need to normaliz
e
> data like this, is there? I won't use it for searches or anything.
> If anyone has a compelling reason why I shouldn't do this, please share,
> please, please.
>
What reason would you have for NOT normalizing in this case?
You seem to be making something very simple into something very
complex. No question in my mind: One table in Normal Form. The keys
would be I assume (customer, order_index) and (customer, order_id).
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||I've upset JC?
(who is JC? Like Jesus Christ JC or is there a NG regular named JC?)
Yes, the data does belong to the database. I'll tell you why; given my
example, it sounds like an app preference or user preference, but this
ordering is actually used to generate source code. If a user logs in at
location A and initiates a build without knowing the ordering of the
records, that would result in invalid firmware and an irritated customer.
This is a feature I should have added from the get go, but I overlooked it.
So moving forward and agreeing (I assume we agree?) that the data does
belong in the DB, is this a valid case for a delimited string?
If not, make your case. I want to learn the right way.
Thanks,
Steve
"Alan Samet" <alansamet@.gmail.com> wrote in message
news:1141943305.488882.121840@.u72g2000cwu.googlegroups.com...
>I have a feeling you're about to feel the wrath of JC.
> But to answer your question, you would create a single table for this.
> I see what you mean by your sorting information. In that case, I
> consider that type of data to not have anything to do with the database
> -- while it's human readable and client readable, I consider the data
> to be arbitrary to anything accessing it within the database. It might
> as well be random binary data for all your database is concerned. Now,
> the question is, does this data belong in your database? You're
> breaking encapsulation by storing this in your database if it's not
> specific to the data. I make two exceptions to putting
> application-specific data within a database. The first is when the
> database is used by one and only one application, and will be used by
> one and only one application for the purpose of storing data and logic
> specific to that application. The second is when the performance or
> implementation advantages of storing such application-specific logic
> and data are exceptionally significant.
> -Alan
>|||>> So I can just have a delimited string stored in a field [sic] called"OrderOrde
ring" (stupid name, my actual name would be "ProtocolOrdering" but sticking
with the example....) something like:4;2;7;1;3;5 <<
Once more, you missed the most basic concepts again! Look up "First
Normal Form" (1NF), and learn why a column is not a field, a row is not
a record and a table is not a file. You might want to read at least
one book on RDBMS before you code in SQL.|||>I've upset JC?
>(who is JC? Like Jesus Christ JC or is there a NG regular named JC?)
I think you've probably figured this out by now.
So, you've decided to keep this in your database. Be aware of the
possible future implications of this. If you store multiple values a
single row, those values will be utterly useless in your database and
you'll be forced to do your sorting on the client. Next, if you dump
your front-end and it's rewritten, you'll have this artifact in your
database that those inheriting your work won't know what to do with
(or, given enough time, you won't either). In this situation, where
you've decided to store application-specific data in your database, at
least make it friendly to whoever may be administering thing. Store
your application-specific data in an application-specific location --
either a "helper" database that is specific to your application, or in
tables that are clearly indicated as being specific to your application
(e.g. App_MyApplication_InvoiceSorting) so that it's known they can be
dropped without implications once your application is no longer used.
-Alan|||>> 've upset JC? (who is JC? Like Jesus Christ JC or is there a NG regular
named JC?) <<
This si why I go by "--CELKO--" in the Newsgroup; peopel keep getting
us all the time.
hout knowing the ordering of the records [sic], that would result in invalid firm
ware and an irritated customer. <<
So the ordering has logical meanng in the data model!
So moving forward and agreeing (I assume we agree?) that the data does
belong in the DB, is this a valid case for a delimited string? <<
NO, it is a valid reason for a sequencing column in First Normal Form.
Since you will not post any DDL or even helpful narrative with
meaningful names, here is a guess:
CREATE TABLE FirmwareTemplates
(customer_id INTEGER NOT NULL
REFERENCES Custromers (customer_id),
template_seq INTEGER NOT NULL,
template_txt VARCHAR (255) NOT NULL,
PRIMARY KEY (customer_id, template_seq ));|||LOL.. let the NG lashings begin!
My entire database is application specific to a single app. It's entire
reason for existence is my application. It would seem in that case that ALL
my data is application specific. Is that bad? I'm getting the distinct
feeling that is somehow a bad thing?
Either way, yes, I am doing the sorting on the client. This is intentional.
My application is a high level firmware editor for our sales people. We
sell a product that can be customized (a bit) per customer. However, ALL
device's firmware must share some data that is constant.
One of the things that can be customized is the ordering of menu items in a
UI menu. All devices have the same menu items, but some customers want them
in a different order. I have approached this by maintaing a base shared
collection of menu items that all customers use. When they want to reorder
the items I store "meta data" (I'm not even sure if I understand that term,
seems like "settings" to me, but whatever) in their record.
Point is, I don't return a separate set of ordered menu item records for
each customer, I get the menu items for all customers, then the ordering
data for each customer, then on the client each customer has a reference to
the shared items and I order them the way they want in the UI.
Hope that makes a bit of sense.
"Alan Samet" <alansamet@.gmail.com> wrote in message
news:1141944627.875280.107100@.i40g2000cwc.googlegroups.com...
> I think you've probably figured this out by now.
> So, you've decided to keep this in your database. Be aware of the
> possible future implications of this. If you store multiple values a
> single row, those values will be utterly useless in your database and
> you'll be forced to do your sorting on the client. Next, if you dump
> your front-end and it's rewritten, you'll have this artifact in your
> database that those inheriting your work won't know what to do with
> (or, given enough time, you won't either). In this situation, where
> you've decided to store application-specific data in your database, at
> least make it friendly to whoever may be administering thing. Store
> your application-specific data in an application-specific location --
> either a "helper" database that is specific to your application, or in
> tables that are clearly indicated as being specific to your application
> (e.g. App_MyApplication_InvoiceSorting) so that it's known they can be
> dropped without implications once your application is no longer used.
> -Alan
>|||"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1141944759.875765.197440@.e56g2000cwe.googlegroups.com...
> This si why I go by "--CELKO--" in the Newsgroup; peopel keep getting
> us all the time.

>
> So the ordering has logical meanng in the data model!
yes, yes it does.

>
> So moving forward and agreeing (I assume we agree?) that the data does
> belong in the DB, is this a valid case for a delimited string? <<
> NO, it is a valid reason for a sequencing column in First Normal Form.
> Since you will not post any DDL or even helpful narrative with
> meaningful names, here is a guess:

> CREATE TABLE FirmwareTemplates
> (customer_id INTEGER NOT NULL
> REFERENCES Custromers (customer_id),
> template_seq INTEGER NOT NULL,
> template_txt VARCHAR (255) NOT NULL,
> PRIMARY KEY (customer_id, template_seq ));
>
Gotcha, I will investigate this, thanks for the suggestion!

Thursday, March 22, 2012

Create Stored Procedure help ...

Hello Every1,
I'm trying to create a stored procedure which will do the following.
- Look at the table to determine if a customer has a duplicate value in
a column.
- If Yes, then replace the duplicate with the highest # for that column
for that particular customer.
- Loop through to check & update all customers.
I was reading SQL Server Books, but couldn't find any help.
Any help or suggestions would be highly appreciated.
Thanks
I don't understand what you want to do. Can you show share sample data
"Tony Schplik" wrote:

> Hello Every1,
> I'm trying to create a stored procedure which will do the following.
> - Look at the table to determine if a customer has a duplicate value in
> a column.
> - If Yes, then replace the duplicate with the highest # for that column
> for that particular customer.
> - Loop through to check & update all customers.
> I was reading SQL Server Books, but couldn't find any help.
> Any help or suggestions would be highly appreciated.
>
> Thanks
>
|||Thanks Arun for your quick reply.
Here is the sample of the data.
CUST_ID SEQ_NUM
6000010135 2
6000010135 1
6000010135 1
6000010135 2
6000010135 5
6000020512 1
6000020512 1
6000020512 1
6000020512 4
6000020512 4
6000020512 6
Hope this will give you a better picture. As you can see from the
sample data that I have customer with same SEQ_NUM, which is causing
problem.
What I have to do is to replace the next same SEQ_NUM for the same
customer with the highest.
So for customer '6000010135' after the update in the table in the
SEQ_NUM column I should have the following values.
2
1
6
7
5
Thanks in advance for your help
|||Does SEQ_NO have any implicit meaning in the data? Can we set any values to
this field as long as they are unique?
if so then it is very easy. Just create a temp table
(seq_no int identity(1,1), customerid int) and do this:
insert temp(customerid) select customerid from my_table order by customerid
One problem here is that seq_no field here will not reset to 1 when a new
customer id starts. So your seq_no will be ever increasing. May not be an
issue if your seq_no field does not have any contextual significance.
Anothe easy way is to use a cursor to go over
select customerid, seq_no from mytable order by customerid, seq_no
and iterate through the records. remember the last pair processed. If this
pair is same, update seq_no with max + 1
There should be a set based solution here too. But i have not figured it out
still.
"Tony Schplik" wrote:

> Thanks Arun for your quick reply.
> Here is the sample of the data.
> CUST_ID SEQ_NUM
> 6000010135 2
> 6000010135 1
> 6000010135 1
> 6000010135 2
> 6000010135 5
> 6000020512 1
> 6000020512 1
> 6000020512 1
> 6000020512 4
> 6000020512 4
> 6000020512 6
> Hope this will give you a better picture. As you can see from the
> sample data that I have customer with same SEQ_NUM, which is causing
> problem.
> What I have to do is to replace the next same SEQ_NUM for the same
> customer with the highest.
> So for customer '6000010135' after the update in the table in the
> SEQ_NUM column I should have the following values.
> 2
> 1
> 6
> 7
> 5
> Thanks in advance for your help
>

Create Stored Procedure help ...

Hello Every1,
I'm trying to create a stored procedure which will do the following.
- Look at the table to determine if a customer has a duplicate value in
a column.
- If Yes, then replace the duplicate with the highest # for that column
for that particular customer.
- Loop through to check & update all customers.
I was reading SQL Server Books, but couldn't find any help.
Any help or suggestions would be highly appreciated.
ThanksI don't understand what you want to do. Can you show share sample data
"Tony Schplik" wrote:
> Hello Every1,
> I'm trying to create a stored procedure which will do the following.
> - Look at the table to determine if a customer has a duplicate value in
> a column.
> - If Yes, then replace the duplicate with the highest # for that column
> for that particular customer.
> - Loop through to check & update all customers.
> I was reading SQL Server Books, but couldn't find any help.
> Any help or suggestions would be highly appreciated.
>
> Thanks
>|||Thanks Arun for your quick reply.
Here is the sample of the data.
CUST_ID SEQ_NUM
6000010135 2
6000010135 1
6000010135 1
6000010135 2
6000010135 5
6000020512 1
6000020512 1
6000020512 1
6000020512 4
6000020512 4
6000020512 6
Hope this will give you a better picture. As you can see from the
sample data that I have customer with same SEQ_NUM, which is causing
problem.
What I have to do is to replace the next same SEQ_NUM for the same
customer with the highest.
So for customer '6000010135' after the update in the table in the
SEQ_NUM column I should have the following values.
2
1
6
7
5
Thanks in advance for your help|||Does SEQ_NO have any implicit meaning in the data? Can we set any values to
this field as long as they are unique?
if so then it is very easy. Just create a temp table
(seq_no int identity(1,1), customerid int) and do this:
insert temp(customerid) select customerid from my_table order by customerid
One problem here is that seq_no field here will not reset to 1 when a new
customer id starts. So your seq_no will be ever increasing. May not be an
issue if your seq_no field does not have any contextual significance.
Anothe easy way is to use a cursor to go over
select customerid, seq_no from mytable order by customerid, seq_no
and iterate through the records. remember the last pair processed. If this
pair is same, update seq_no with max + 1
There should be a set based solution here too. But i have not figured it out
still.
"Tony Schplik" wrote:
> Thanks Arun for your quick reply.
> Here is the sample of the data.
> CUST_ID SEQ_NUM
> 6000010135 2
> 6000010135 1
> 6000010135 1
> 6000010135 2
> 6000010135 5
> 6000020512 1
> 6000020512 1
> 6000020512 1
> 6000020512 4
> 6000020512 4
> 6000020512 6
> Hope this will give you a better picture. As you can see from the
> sample data that I have customer with same SEQ_NUM, which is causing
> problem.
> What I have to do is to replace the next same SEQ_NUM for the same
> customer with the highest.
> So for customer '6000010135' after the update in the table in the
> SEQ_NUM column I should have the following values.
> 2
> 1
> 6
> 7
> 5
> Thanks in advance for your help
>

Create Stored Procedure help ...

Hello Every1,
I'm trying to create a stored procedure which will do the following.
- Look at the table to determine if a customer has a duplicate value in
a column.
- If Yes, then replace the duplicate with the highest # for that column
for that particular customer.
- Loop through to check & update all customers.
I was reading SQL Server Books, but couldn't find any help.
Any help or suggestions would be highly appreciated.
ThanksI don't understand what you want to do. Can you show share sample data
"Tony Schplik" wrote:

> Hello Every1,
> I'm trying to create a stored procedure which will do the following.
> - Look at the table to determine if a customer has a duplicate value in
> a column.
> - If Yes, then replace the duplicate with the highest # for that column
> for that particular customer.
> - Loop through to check & update all customers.
> I was reading SQL Server Books, but couldn't find any help.
> Any help or suggestions would be highly appreciated.
>
> Thanks
>|||Thanks Arun for your quick reply.
Here is the sample of the data.
CUST_ID SEQ_NUM
6000010135 2
6000010135 1
6000010135 1
6000010135 2
6000010135 5
6000020512 1
6000020512 1
6000020512 1
6000020512 4
6000020512 4
6000020512 6
Hope this will give you a better picture. As you can see from the
sample data that I have customer with same SEQ_NUM, which is causing
problem.
What I have to do is to replace the next same SEQ_NUM for the same
customer with the highest.
So for customer '6000010135' after the update in the table in the
SEQ_NUM column I should have the following values.
2
1
6
7
5
Thanks in advance for your help|||Does SEQ_NO have any implicit meaning in the data? Can we set any values to
this field as long as they are unique?
if so then it is very easy. Just create a temp table
(seq_no int identity(1,1), customerid int) and do this:
insert temp(customerid) select customerid from my_table order by customerid
One problem here is that seq_no field here will not reset to 1 when a new
customer id starts. So your seq_no will be ever increasing. May not be an
issue if your seq_no field does not have any contextual significance.
Anothe easy way is to use a cursor to go over
select customerid, seq_no from mytable order by customerid, seq_no
and iterate through the records. remember the last pair processed. If this
pair is same, update seq_no with max + 1
There should be a set based solution here too. But i have not figured it out
still.
"Tony Schplik" wrote:

> Thanks Arun for your quick reply.
> Here is the sample of the data.
> CUST_ID SEQ_NUM
> 6000010135 2
> 6000010135 1
> 6000010135 1
> 6000010135 2
> 6000010135 5
> 6000020512 1
> 6000020512 1
> 6000020512 1
> 6000020512 4
> 6000020512 4
> 6000020512 6
> Hope this will give you a better picture. As you can see from the
> sample data that I have customer with same SEQ_NUM, which is causing
> problem.
> What I have to do is to replace the next same SEQ_NUM for the same
> customer with the highest.
> So for customer '6000010135' after the update in the table in the
> SEQ_NUM column I should have the following values.
> 2
> 1
> 6
> 7
> 5
> Thanks in advance for your help
>

Sunday, March 11, 2012

Create or modify MSDE Database

Hi,
On Administrator session, I have created an CUSTOMER MSDE database. That's OK.

On user session, I want to access on my database CUSTOMER but I have on error : "Unable to connect to the database". And, in French : "Echec de la connexion de l'utilisateur Machine_Name/User_Name".

What is the error ? I don't know what to do any more.
How to give right to the user ? Have you an idea ?

Thank's.

Patrice A. BONNEFOY.Did you create a username to use to gain access to the MSDE database? If you're using Windows authentication then you need to add a user like Machine_Name/ASPNET. If you are using Sql authentication then you have to add some username or use an existing one.

This link may helpful for doing this|||Hi,
Thank you for your assistance. Now, I think of being able to repair me.

Best regards.
Patrice BONNEFOY.
www.pabonnefoy.net/

Friday, February 17, 2012

Create Database using C#

Hi,
I write software in C# that should create (by itself) a new database.
The SQL server should be installed on the customer's computers silently
(I still need to figure how to do this part)
How can my software create a database that only it can access? Do I
need to create a special user account from the software?
What user account do I use to open a connection to the SQL server in
the first place when I create the database (taking under consideration
that the SQL server was installed silently and as far as the user
concern he has no idea my software uses SQL server).
To summarize:
1. The install of my software should install and configure the SQL
server silently (appreciate any help here)
2. The software needs to access the local SQL server and create a
database that only it can access when the software runs under a simple
"USER" account in Win2K/XP and not "ADMINISTRATOR" (my big problem -
any idea?)
Thanks in advance,
Oren"orenbt78" <orenbt78@.googlemail.com> wrote in message
news:1164123542.578586.6280@.j44g2000cwa.googlegroups.com...
> Hi,
> I write software in C# that should create (by itself) a new database.
> The SQL server should be installed on the customer's computers silently
> (I still need to figure how to do this part)
> How can my software create a database that only it can access? Do I
> need to create a special user account from the software?
> What user account do I use to open a connection to the SQL server in
> the first place when I create the database (taking under consideration
> that the SQL server was installed silently and as far as the user
> concern he has no idea my software uses SQL server).
> To summarize:
> 1. The install of my software should install and configure the SQL
> server silently (appreciate any help here)
> 2. The software needs to access the local SQL server and create a
> database that only it can access when the software runs under a simple
> "USER" account in Win2K/XP and not "ADMINISTRATOR" (my big problem -
> any idea?)
> Thanks in advance,
> Oren
>
See
Embedding SQL Server Express into Custom Applications
http://msdn.microsoft.com/library/d...>
xcustapp.asp
User Instances for Non-Administrators
http://msdn2.microsoft.com/en-us/library/ms143684.aspx
David|||Thanx for the reply.
The "Embedding SQL Server Express into Custom Applications" seems to be
very helpful.
However, I can't figure out yet how to solve my problem with creating
databases as a simply user.
I plan to create a new database every year and let the user to view
last year's data while I am updating this year's data. That means 2
connections at the same time.
In the "User Instances for Non-Administrators" document it says "One
user can only have one user instance". So how can I do that?
And how do I do it in C# code?
Thanks again,
Oren|||"orenbt78" <orenbt78@.googlemail.com> wrote in message
news:1164565596.943159.13410@.14g2000cws.googlegroups.com...
> Thanx for the reply.
> The "Embedding SQL Server Express into Custom Applications" seems to be
> very helpful.
> However, I can't figure out yet how to solve my problem with creating
> databases as a simply user.
> I plan to create a new database every year and let the user to view
> last year's data while I am updating this year's data. That means 2
> connections at the same time.
> In the "User Instances for Non-Administrators" document it says "One
> user can only have one user instance". So how can I do that?
> And how do I do it in C# code?
An instance is an instance of the database engine. A single instance of the
database engine can have multiple databases.
And in C# you just send TSQL commands using a
System.Data.SqlClient.SqlCommand object. You can get the syntax for the
commands from SQL Server Books Online.
TDavid|||I have managed to create the database file (code below). I am not sure
it is the right way.
I would like to create a password for these database so only my
software will be able to control it (change data). how do i do that?
tmpConn.ConnectionString = "Data Source=(local); DATABASE =
master;Integrated Security=True; user instance=true";
sqlCreateDBQuery = " CREATE DATABASE " + DBParam.DatabaseName + " ON
PRIMARY "
+ " (NAME = " + DBParam.DataFileName +", "
+ " FILENAME = '" + DBParam.DataPathName +"', "
+ " SIZE = 5MB,"
+ " FILEGROWTH =" + DBParam.DataFileGrowth +") "
+ " LOG ON (NAME =" + DBParam.LogFileName +", "
+ " FILENAME = '" + DBParam.LogPathName + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH =" + DBParam.LogFileGrowth +") ";
SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
MessageBox.Show(sqlCreateDBQuery);
myCommand.ExecuteNonQuery();
MessageBox.Show("Database has been created successfully!", "Create
Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "Create Database",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
tmpConn.Close();
}|||anyone? any idea?

Create Database using C#

Hi,
I write software in C# that should create (by itself) a new database.
The SQL server should be installed on the customer's computers silently
(I still need to figure how to do this part)
How can my software create a database that only it can access? Do I
need to create a special user account from the software?
What user account do I use to open a connection to the SQL server in
the first place when I create the database (taking under consideration
that the SQL server was installed silently and as far as the user
concern he has no idea my software uses SQL server).
To summarize:
1. The install of my software should install and configure the SQL
server silently (appreciate any help here)
2. The software needs to access the local SQL server and create a
database that only it can access when the software runs under a simple
"USER" account in Win2K/XP and not "ADMINISTRATOR" (my big problem -
any idea?)
Thanks in advance,
Oren"orenbt78" <orenbt78@.googlemail.com> wrote in message
news:1164123542.578586.6280@.j44g2000cwa.googlegroups.com...
> Hi,
> I write software in C# that should create (by itself) a new database.
> The SQL server should be installed on the customer's computers silently
> (I still need to figure how to do this part)
> How can my software create a database that only it can access? Do I
> need to create a special user account from the software?
> What user account do I use to open a connection to the SQL server in
> the first place when I create the database (taking under consideration
> that the SQL server was installed silently and as far as the user
> concern he has no idea my software uses SQL server).
> To summarize:
> 1. The install of my software should install and configure the SQL
> server silently (appreciate any help here)
> 2. The software needs to access the local SQL server and create a
> database that only it can access when the software runs under a simple
> "USER" account in Win2K/XP and not "ADMINISTRATOR" (my big problem -
> any idea?)
> Thanks in advance,
> Oren
>
See
Embedding SQL Server Express into Custom Applications
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsse/html/emsqlexcustapp.asp
User Instances for Non-Administrators
http://msdn2.microsoft.com/en-us/library/ms143684.aspx
David|||Thanx for the reply.
The "Embedding SQL Server Express into Custom Applications" seems to be
very helpful.
However, I can't figure out yet how to solve my problem with creating
databases as a simply user.
I plan to create a new database every year and let the user to view
last year's data while I am updating this year's data. That means 2
connections at the same time.
In the "User Instances for Non-Administrators" document it says "One
user can only have one user instance". So how can I do that?
And how do I do it in C# code?
Thanks again,
Oren|||"orenbt78" <orenbt78@.googlemail.com> wrote in message
news:1164565596.943159.13410@.14g2000cws.googlegroups.com...
> Thanx for the reply.
> The "Embedding SQL Server Express into Custom Applications" seems to be
> very helpful.
> However, I can't figure out yet how to solve my problem with creating
> databases as a simply user.
> I plan to create a new database every year and let the user to view
> last year's data while I am updating this year's data. That means 2
> connections at the same time.
> In the "User Instances for Non-Administrators" document it says "One
> user can only have one user instance". So how can I do that?
> And how do I do it in C# code?
An instance is an instance of the database engine. A single instance of the
database engine can have multiple databases.
And in C# you just send TSQL commands using a
System.Data.SqlClient.SqlCommand object. You can get the syntax for the
commands from SQL Server Books Online.
TDavid|||I have managed to create the database file (code below). I am not sure
it is the right way.
I would like to create a password for these database so only my
software will be able to control it (change data). how do i do that?
tmpConn.ConnectionString = "Data Source=(local); DATABASE =master;Integrated Security=True; user instance=true";
sqlCreateDBQuery = " CREATE DATABASE " + DBParam.DatabaseName + " ON
PRIMARY "
+ " (NAME = " + DBParam.DataFileName +", "
+ " FILENAME = '" + DBParam.DataPathName +"', "
+ " SIZE = 5MB,"
+ " FILEGROWTH =" + DBParam.DataFileGrowth +") "
+ " LOG ON (NAME =" + DBParam.LogFileName +", "
+ " FILENAME = '" + DBParam.LogPathName + "', "
+ " SIZE = 1MB, "
+ " FILEGROWTH =" + DBParam.LogFileGrowth +") ";
SqlCommand myCommand = new SqlCommand(sqlCreateDBQuery, tmpConn);
try
{
tmpConn.Open();
MessageBox.Show(sqlCreateDBQuery);
myCommand.ExecuteNonQuery();
MessageBox.Show("Database has been created successfully!", "Create
Database", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString(), "Create Database",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
tmpConn.Close();
}|||anyone? any idea?

Tuesday, February 14, 2012

Create Database gives Device Activation Error (5105)

Hello NG,
Creating a new database using T-SQL Create Database [MyName] used to work on
my customer's installation.
Now, it gives a Device Activation Error with error nr 5105, indicating that
MyName.mdf may be incorrect.
Nothing has changed (they claim), and I don't know why this message shows up
nor how to correct the situation.
Any help will be appreciated.
Thanks,
Hans van Leth.Hi Hans.
Can you post the full message please?
Sure - they all say "nothing's changed"!! I don't mean to question your
client's integrity, but perhaps they don't realise that a change on a non
SQL Server component might actually affect SQL Server. For example,
permissions might have changed either locally or on the AD perhaps.
If you've performed this before & it now suddenly fails, it's more than
likely that SOMETHING has changed!
Regards,
Greg Linwood
SQL Server MVP
"Hans van Leth" <hans.v.l bij xs4all.nl> wrote in message
news:evH#BqNgDHA.1760@.TK2MSFTNGP09.phx.gbl...
> Hello NG,
> Creating a new database using T-SQL Create Database [MyName] used to work
on
> my customer's installation.
> Now, it gives a Device Activation Error with error nr 5105, indicating
that
> MyName.mdf may be incorrect.
> Nothing has changed (they claim), and I don't know why this message shows
up
> nor how to correct the situation.
> Any help will be appreciated.
> Thanks,
> Hans van Leth.
>
>|||Hello Greg,
Executing "Create database test1" in QA gives:
Server: Msg 5105, Level 16, State 2, Line 1
Device activation error. The physical file name '\test1.mdf' may be
incorrect.
Server: Msg 1802, Level 16, State 1, Line 1
CREATE DATABASE failed. Some file names listed could not be created.
Check previous errors.
Creating a new database test1 in EM does work however. In Profiler I can see
that EM sends the full Create statement, i.e. including the filename as in:
CREATE DATABASE [test1] ON (NAME = N'test1_Data', FILENAME = N'C:\Program
Files\Microsoft SQL Server\MSSQL\Data\test1_Data.MDF')
The user uses an accounting package and for each company a new database is
created using the statement as mentioned.
This used to work and now it doesn't...
If I had the sources to the package I would change the Create statement to
include the filename but unfortunately it doesn't...
BOL states that including the filesnames is not required.
SQL Server default file locations are set to the ..\MSSQL\Data directory as
above.
Thanks for your time!
Hans van Leth.
"Greg Linwood" <g_linwood@.hotmail.com> schreef in bericht
news:OoB5edQgDHA.3200@.tk2msftngp13.phx.gbl...
> Hi Hans.
> Can you post the full message please?
> Sure - they all say "nothing's changed"!! I don't mean to question your
> client's integrity, but perhaps they don't realise that a change on a non
> SQL Server component might actually affect SQL Server. For example,
> permissions might have changed either locally or on the AD perhaps.
> If you've performed this before & it now suddenly fails, it's more than
> likely that SOMETHING has changed!
> Regards,
> Greg Linwood
> SQL Server MVP
> "Hans van Leth" <hans.v.l bij xs4all.nl> wrote in message
> news:evH#BqNgDHA.1760@.TK2MSFTNGP09.phx.gbl...
> > Hello NG,
> >
> > Creating a new database using T-SQL Create Database [MyName] used to
work
> on
> > my customer's installation.
> > Now, it gives a Device Activation Error with error nr 5105, indicating
> that
> > MyName.mdf may be incorrect.
> > Nothing has changed (they claim), and I don't know why this message
shows
> up
> > nor how to correct the situation.
> > Any help will be appreciated.
> >
> > Thanks,
> >
> > Hans van Leth.
> >
> >
> >
> >
>|||Do you have a way of examining the directories involved? Perhaps there's an
existing .MDF/.LDF file with the name you intend to use?
Are you trying to create the device on C:? Have you checked your server
properties (right-click server name in EM) for the default database/log
locations and verified that they are OK ("Database Settings" tab in that
"SQL Server Properties" dialog box).
I reproduced a 5105 by inserting an incorrect device letter at the beginning
of the string - I expect any malformed or incorrect filespec would give the
same result.
"Hans van Leth" <hans.v.l bij xs4all.nl> wrote in message
news:epVGfzQgDHA.632@.TK2MSFTNGP10.phx.gbl...
> Hello Greg,
> Executing "Create database test1" in QA gives:
> Server: Msg 5105, Level 16, State 2, Line 1
> Device activation error. The physical file name '\test1.mdf' may be
> incorrect.
> Server: Msg 1802, Level 16, State 1, Line 1
> CREATE DATABASE failed. Some file names listed could not be created.
> Check previous errors.
> Creating a new database test1 in EM does work however. In Profiler I can
see
> that EM sends the full Create statement, i.e. including the filename as
in:
> CREATE DATABASE [test1] ON (NAME = N'test1_Data', FILENAME = N'C:\Program
> Files\Microsoft SQL Server\MSSQL\Data\test1_Data.MDF')
> The user uses an accounting package and for each company a new database is
> created using the statement as mentioned.
> This used to work and now it doesn't...
> If I had the sources to the package I would change the Create statement to
> include the filename but unfortunately it doesn't...
> BOL states that including the filesnames is not required.
> SQL Server default file locations are set to the ..\MSSQL\Data directory
as
> above.
> Thanks for your time!
> Hans van Leth.
>
> "Greg Linwood" <g_linwood@.hotmail.com> schreef in bericht
> news:OoB5edQgDHA.3200@.tk2msftngp13.phx.gbl...
> > Hi Hans.
> >
> > Can you post the full message please?
> >
> > Sure - they all say "nothing's changed"!! I don't mean to question your
> > client's integrity, but perhaps they don't realise that a change on a
non
> > SQL Server component might actually affect SQL Server. For example,
> > permissions might have changed either locally or on the AD perhaps.
> >
> > If you've performed this before & it now suddenly fails, it's more than
> > likely that SOMETHING has changed!
> >
> > Regards,
> > Greg Linwood
> > SQL Server MVP
> >
> > "Hans van Leth" <hans.v.l bij xs4all.nl> wrote in message
> > news:evH#BqNgDHA.1760@.TK2MSFTNGP09.phx.gbl...
> > > Hello NG,
> > >
> > > Creating a new database using T-SQL Create Database [MyName] used to
> work
> > on
> > > my customer's installation.
> > > Now, it gives a Device Activation Error with error nr 5105, indicating
> > that
> > > MyName.mdf may be incorrect.
> > > Nothing has changed (they claim), and I don't know why this message
> shows
> > up
> > > nor how to correct the situation.
> > > Any help will be appreciated.
> > >
> > > Thanks,
> > >
> > > Hans van Leth.
> > >
> > >
> > >
> > >
> >
> >
>|||This is a bug. Here's what caused your error; if you go to the server
properties and specify a default location for the database\log files in
EM (Enterprise Manager), a registry entry is made on the server called
'DEFAULTDATA' & 'DEFAULTLOG' under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer.
If you ever delete the default data\log locations EM doesn't clean up
the registry correctly, it deletes the values in the keys, when if needs
to delete the keys (DEFAULTDATA & DEFAULTLOG) altogether.
So, if you delete the keys manually and restart the SQL Server
instance you'll be back in business. If you delete the keys but don't
restart the service the error is still present. Restart of the
service is required.
Posted via http://dbforums.com

Create Customer Ranking in Cube

Hey guys,

is there a way i can create a Rank Member or measure in my cube based on sales for that customer, no matter what time heirarchy we are looking at.

I have reporting requirements where they want to see all customers, ordered by Sales Amount. It could be at a year level, month level, or even a week/day level..

Im new to SSAS and MDX, i have looked at a few examples posted here, but cannot work out where i put the script in my cube. Is it a measure or do i do it as a calculated column in the DSV.

Any help is much appreciated.

Thanks

Scotty

Here's an Adventure Works ranking query, which uses a query-scoped calculated measure (assuming that the Customer hierarchy is on the rows of the query):

>>

with member [Measures].[CustSalesRank] as

Rank([Customer].[Customer Geography].CurrentMember,

Order(Extract(Axis(1),[Customer].[Customer Geography]),

[Measures].[Internet Sales Amount], BDESC)),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount]

select [Date].[Fiscal Year].Members *

{[Measures].[Internet Sales Amount], [Measures].[CustSalesRank]} on 0,

NON EMPTY [Customer].[Customer Geography].[Country].Members on 1

from [Adventure Works]

--

All Periods All Periods FY 2002 FY 2002 FY 2003 FY 2003 FY 2004 FY 2004 FY 2005 FY 2005
Internet Sales Amount CustSalesRank Internet Sales Amount CustSalesRank Internet Sales Amount CustSalesRank Internet Sales Amount CustSalesRank Internet Sales Amount CustSalesRank
Australia $9,061,000.58 2 $2,568,701.39 1 $2,099,585.43 1 $4,383,479.54 2 $9,234.23 3
Canada $1,977,844.86 6 $573,100.97 3 $305,010.69 6 $1,088,879.50 6 $10,853.70 2
France $2,644,017.71 5 $414,245.32 6 $633,399.70 4 $1,592,880.75 5 $3,491.95 6
Germany $2,894,312.34 4 $513,353.17 5 $593,247.24 5 $1,784,107.09 4 $3,604.83 5
United Kingdom $3,391,712.21 3 $550,507.33 4 $696,594.97 3 $2,140,388.50 3 $4,221.41 4
United States $9,389,789.51 1 $2,452,176.07 2 $1,434,296.26 2 $5,483,882.67 1 $19,434.51 1

>>

|||Please remove this line, as it is wrong:

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount]

Obviously, even if [Internet Sales Amount] is NULL, the rank will never be NULL - it is always an integer value.

|||

Ok guys, thanks for the replys..

I added the following into a calculated measure that i called CustSalesRank .. (taken from the 1st line of code) is that Correct?

When i added this to the expression box in the calculated member, i get a red undeline on the "with" statement.. What am i doing wrong?

CREATE MEMBER CURRENTCUBE.[MEASURES].[CustSalesRank]

AS with member [measures].[CustSalesRank] as

Rank([Customer].[Customer Group Name].CurrentMember,

Order(Extract(Axis(1),[Customer].[Customer Group Name]),

[Measures].[Sales Amount], BDESC)),

select [Date].[Fiscal Hierarchy].Members *

{[Measures].[Sales Amount], [Measures].[CustSalesRank]} on 0,

NON EMPTY [Customer].[Customer Group Name].Members on 1

from [Sales By Market],

VISIBLE = 1 ;

--

|||

the error i get when i try to deploy is:

Error 2 MdxScript(Sales By Market) (17, 5) Parser: The syntax for 'with' is incorrect. 0 0

|||

Hi Mosha,

You're right in the strict sense - the reason I added NON_EMPTY_BEHAVIOR was to remove rows with no sales for this specific query (ie. a query ranking only among customers with sales data), as in this example:

>>

with member [Measures].[CustSalesRank] as

Rank([Customer].[Customer Geography].CurrentMember,

Order(Extract(Axis(1),[Customer].[Customer Geography]),

[Measures].[Internet Sales Amount], BDESC))

select

{[Measures].[Internet Sales Amount], [Measures].[CustSalesRank]} on 0,

NON EMPTY DrillDownLevel([Customer].[Customer Geography].[Country].&[Canada]) on 1

from [Adventure Works]

-

Internet Sales Amount CustSalesRank
Canada $1,977,844.86 1
Alberta $22,467.80 3
British Columbia $1,955,340.10 2
Brunswick (null) 5
Manitoba (null) 6
Ontario $36.96 4
Quebec (null) 7

versus:

with member [Measures].[CustSalesRank] as

Rank([Customer].[Customer Geography].CurrentMember,

Order(Extract(Axis(1),[Customer].[Customer Geography]),

[Measures].[Internet Sales Amount], BDESC)),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount]

select

{[Measures].[Internet Sales Amount], [Measures].[CustSalesRank]} on 0,

NON EMPTY DrillDownLevel([Customer].[Customer Geography].[Country].&[Canada]) on 1

from [Adventure Works]

-

Internet Sales Amount CustSalesRank
Canada $1,977,844.86 1
Alberta $22,467.80 3
British Columbia $1,955,340.10 2
Ontario $36.96 4

>>

|||

> You're right in the strict sense - the reason I added NON_EMPTY_BEHAVIOR was to remove rows with no sales for this specific query (ie. a query ranking only among customers with sales data), as in this example:

Deepak - this is very very dangerous path. NON_EMPTY_BEHAVIOR is not a semantic feature, it is a performance hint. It doesn't cause rows to be removed by NON EMPTY. They might get removed sometimes when NEB is defined incorrectly, like in the example above, but it is purely a hint, and in other situations they won't get removed. So you will get inconsistant and even wrong results.

To properly remove rows with no sales, there must be specific IIF for that, i.e.

with member [Measures].[CustSalesRank] as

IIF( IsEmpty([Measures].[Internet Sales Amount]), NULL, Rank([Customer].[Customer Geography].CurrentMember,

Order(Extract(Axis(1),[Customer].[Customer Geography]),

[Measures].[Internet Sales Amount], BDESC))),

NON_EMPTY_BEHAVIOR = [Measures].[Internet Sales Amount]

Now NON_EMPTY_BEHAVIOR is correctly defined. Another idea is to optimize performance here would be to remove Order from inside Rank, and use version of Rank with 3 parameters.

|||

Mosha,

Thanks for your input.. Could you please kindly answer my question for me.. I just need to know where i put this code, i put it in a calculated measure and it didnt work. I removed all things from the select statement and down, but im not sure if it is working correctly..

Also, with all this code talk, im not 100% sure what i should be putting in now...

Thanks

Scotty

|||

For Adventure Works, you can put something like that inside MDX Script:

CREATE [CustSalesRank] = Rank([Customer].[Customer Geography].CurrentMember,[Customer].[Customer Geography].CurrentMember.Level.Members,[Measures].[Internet Sales Amount]);

|||

Thanks Mosha.. this worked great..

If i may ask for one more piece of advise, when i do this,, all the customers that have 0 sales are still shown with the lowest rank number.. in my case 81 . what i can i add to expression that will supress customers with 0 sales..?

Thanks

scotty

|||

Thanks for clarifying that, Mosha - I had (mistakenly) assumed that, in AS 2005, NON_EMPTY_BEHAVIOR would cause those rows to be removed.

On the use of Rank() with 3 parameters in lieu of Order() - has the semantics of Rank() changed in AS 2005, because BOL still says the following:

http://msdn2.microsoft.com/en-us/library/ms144726.aspx

>>

SQL Server 2005 Books Online

Rank (MDX)

Updated: 17 July 2006

...

The Rank function does not order the set.

>>

|||

The comment that Rank function doesn not order the set is correct, although I can see how it can be misleading. It probably refers to the fact that internal implementation of Rank doesn't need to order the set in order to find the rank. Please see detailed discussion about Rank and algorithms behind it in this blog:

http://www.sqljunkies.com/WebLog/mosha/archive/2006/03/14/mdx_ranking.aspx

|||

Thanks - since the same comment also appeared in AS 2000 BOL, it could be confusing. But the MDX Solutions chapter, referenced in your blog entry, draws this distinction:

"..The semantics for this function have changed between Analysis Services 2000 and 2005. When the expression is provided, it is used to determine if ties exist and what the right rank should be. In Analysis Services 2000, the expression was used when the tuple was found to search neighbors in the set and determine fair ranking numbers.."