Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

looking for an example of how to create users out of a table in the database.

Posted on 2007-10-01
4
Medium Priority
?
279 Views
Last Modified: 2013-11-26
i need to create users in postgres databases.
i integrate datas from excel files with c# in a new created database,
i need now to get users out of a table and give them rights depending what was entry in the table.
three kind of users....
what 's the best way to do this? do I need to generate a file and then pass to postgres?
with procedures?

i need an advice on how to do it and a description on steps to do.
some code is wellcome or link on code solution.


0
Comment
Question by:toshi_
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
earth man2 earned 600 total points
ID: 19996630
It's usually better to create ROLES that are given the associated privileges rather than assign a multitude of access rights.

To add data from a CSV file you can use the COPY command

COPY tablename [ ( column [, ...] ) ]
    FROM { 'filename' | STDIN }
    [ [ WITH ]
          [ BINARY ]
          [ OIDS ]
          [ DELIMITER [ AS ] 'delimiter' ]
          [ NULL [ AS ] 'null string' ]
          [ CSV [ HEADER ]
                [ QUOTE [ AS ] 'quote' ]
                [ ESCAPE [ AS ] 'escape' ]
                [ FORCE NOT NULL column [, ...] ]

You just need to wrap some plpgsql stored function around that and the CREATE USER, ALTER USER, CREATE ROLE, ALTER ROLE commands.

More work than I'm prepared to do for free!
0
 

Author Comment

by:toshi_
ID: 20022752
ok, lets say that i'll export the data table users to a cvs file
in order to parse it with postgres functions.

what i dont understand is where to start with my prob.
where do i write your commands - COPY tablename[] ....- to start with?  i'll arrange them once i know where to introduce them.
and how do i launch it then ?


i dont need you to do my job earhman, as you're the biggest expert here i don't want to loose your time
,you can give so many answers to people.

if you know a good tutorial on how to do it,  or an article i'll suit me.
i'll be able to ask more precisely then.

thanks in advance, you over guru ;o)


0
 
LVL 10

Assisted Solution

by:adrpo
adrpo earned 400 total points
ID: 20113910

Hi,

As far as I can understand your question you need to create users
in PostgreSQL from excel files using C#. Please correct me if I'm wrong.
First, you need to have the PostgreSQL server running and you need
to connect to it from C# in order to send it commands.
http://postgresql.mirrors-r-us.net/docs/techdocs-34.html

I would start here with PosgreSQL if you don't have it installed already:
http://www.postgresql.org/docs/8.2/static/index.html
I. Tutorial 1. Getting Started

Another way would be to generate text files with SQL commands from C# and then call (execute)
psql file.sql
to push them into the PostgreSQL database.
http://www.postgresql.org/docs/8.2/static/app-psql.html

Cheers,
za-k/
0
 

Author Comment

by:toshi_
ID: 20122147
hi adrpo,
the first part is done,
i have install xp with pgadminIII which install also the 8.2 postgres server.
i could create user, databases, i create a c# class to connect to postgres,
everything is working.

i' have an xls file with a list of people that will connect read only to database. some of them will have permissions to make changes, a columns in excel file has the type of the user.

as far as i understand now, i have to generate a csv file while parsing my excel file with c#. the csv file will have loginuser and right type.
then i parse that file from postgresql with the call(execute) in order to
create the users and roles for the database.


what would be good practice for doing this,  how to use roles and grouproles?
i need :  "communityUser"  "logisticUser" and "communityAdmin".
should i create three grouproles with the rights, and then create roles and add them to grouproles?

 

0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question