473,394 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

SQL Server Logon

tc
Does anyone have an example of how to connect to an SQL server and create a
new database, then add a user and assign permissions? One problem is that
users may be user authenticated, not Windows authenticated.

Thanks.
Apr 25 '07 #1
3 2988

"tc" <tu**@idcodeware.co.ukwrote in message
news:OR**************@TK2MSFTNGP02.phx.gbl...
Does anyone have an example of how to connect to an SQL server and create
a new database, then add a user and assign permissions? One problem is
that users may be user authenticated, not Windows authenticated.

Thanks.
Do you want to do this programmatically, through scripts or via SQL Server
management tools? In any case, please tell us which version of SQL Server
(2000, 2005, etc) you are using as techniques would be different.
Apr 25 '07 #2
In VB.net
Provider:
SQL2k5 Username / Password:
Provider=SQLNCLI;Server=HostOrIP\Instance;Database =DatabaseName;Uid=myUsername;Pwd=myPassword;
SQL2k5 Trusted Connection:
Provider=SQLNCLI;Server='HostOrIP;Database=Databas eName;Trusted_Connection=yes;
SQL2k Username / Password:
Provider=sqloledb;Data Source=HostOrIP;Initial Catalog=DatabaseName;User
Id=myUsername;Password=myPassword;
SQL2k Trusted Connection:
Provider=sqloledb;Data Source=HostOrIP;Initial
Catalog=DatabaseName;Integrated Security=SSPI;

Dim SQLServer As New Data.OleDb.OleDbConnection
SQLServer.ConnectionString =
"Provider=SQLNCLI;Server=primary\sql2k5;Database=m aster;Trusted_Connection=yes;"
SQLServer.Open()
Dim Command As New Data.OleDb.OleDbCommand
Command.Connection = SQLServer
Command.CommandText = "Create Database test123"
Command.ExecuteNonQuery()
Command.CommandText = "Use test123"
Command.ExecuteNonQuery()
Command.CommandText = "Create Table test (id int identity(1,1),test
nvarchar(50))"
Command.ExecuteNonQuery()

Command.CommandText = "CREATE LOGIN [primary\administrator] FROM
WINDOWS"
Command.ExecuteNonQuery()
Command.CommandText = "CREATE USER [PRIMARY\administrator] FOR LOGIN
[PRIMARY\administrator] WITH DEFAULT_SCHEMA=[dbo]"
Command.ExecuteNonQuery()
Command.CommandText = "Grant ALL to [primary\administrator]"
Command.ExecuteNonQuery()

Command.CommandText = "CREATE LOGIN [test] with Password='test'"
Command.ExecuteNonQuery()
Command.CommandText = "CREATE USER [test] FOR LOGIN [test] WITH
DEFAULT_SCHEMA=[guest]"
Command.ExecuteNonQuery()
Command.CommandText = "Grant SELECT to [test]"
Command.ExecuteNonQuery()

SQLServer.Close()

'SQL2k5 Username / Password:
Provider=SQLNCLI;Server=HostOrIP\Instance;Database =DatabaseName;Uid=myUsername;Pwd=myPassword;
'SQL2k5 Trusted Connection:
Provider=SQLNCLI;Server='HostOrIP;Database=Databas eName;Trusted_Connection=yes;

'SQL2k5 Username / Password: Provider=sqloledb;Data Source=' SQL2k5
Username / Password: ;Initial Catalog=DatabaseName;User
Id=myUsername;Password=myPassword;
'SQL2k5 Trusted Connection: Provider=sqloledb;Data Source=' SQL2k5
Username / Password: ;Initial Catalog=DatabaseName;Integrated Security=SSPI;

Creates a SQL2k5 Database named test123 on primary (instance sqlsk5).
creates a table (test) with 2 fields (id integer as identity and test as
nvarchar). creates 2 user (1 windows, 1 sql) and logins to the new database.
grant full access to the windows- and only-select access to sql-user.

thats all.

"tc" <tu**@idcodeware.co.ukschrieb im Newsbeitrag
news:OR**************@TK2MSFTNGP02.phx.gbl...
Does anyone have an example of how to connect to an SQL server and create
a new database, then add a user and assign permissions? One problem is
that users may be user authenticated, not Windows authenticated.

Thanks.

Apr 25 '07 #3
tc
Many thanks, will start playing tomorrow!

"Matthias Vastring" <in**@vastring.dewrote in message
news:96**********************************@microsof t.com...
In VB.net
Provider:
SQL2k5 Username / Password:
Provider=SQLNCLI;Server=HostOrIP\Instance;Database =DatabaseName;Uid=myUsername;Pwd=myPassword;
SQL2k5 Trusted Connection:
Provider=SQLNCLI;Server='HostOrIP;Database=Databas eName;Trusted_Connection=yes;
SQL2k Username / Password:
Provider=sqloledb;Data Source=HostOrIP;Initial Catalog=DatabaseName;User
Id=myUsername;Password=myPassword;
SQL2k Trusted Connection:
Provider=sqloledb;Data Source=HostOrIP;Initial
Catalog=DatabaseName;Integrated Security=SSPI;

Dim SQLServer As New Data.OleDb.OleDbConnection
SQLServer.ConnectionString =
"Provider=SQLNCLI;Server=primary\sql2k5;Database=m aster;Trusted_Connection=yes;"
SQLServer.Open()
Dim Command As New Data.OleDb.OleDbCommand
Command.Connection = SQLServer
Command.CommandText = "Create Database test123"
Command.ExecuteNonQuery()
Command.CommandText = "Use test123"
Command.ExecuteNonQuery()
Command.CommandText = "Create Table test (id int identity(1,1),test
nvarchar(50))"
Command.ExecuteNonQuery()

Command.CommandText = "CREATE LOGIN [primary\administrator] FROM
WINDOWS"
Command.ExecuteNonQuery()
Command.CommandText = "CREATE USER [PRIMARY\administrator] FOR
LOGIN [PRIMARY\administrator] WITH DEFAULT_SCHEMA=[dbo]"
Command.ExecuteNonQuery()
Command.CommandText = "Grant ALL to [primary\administrator]"
Command.ExecuteNonQuery()

Command.CommandText = "CREATE LOGIN [test] with Password='test'"
Command.ExecuteNonQuery()
Command.CommandText = "CREATE USER [test] FOR LOGIN [test] WITH
DEFAULT_SCHEMA=[guest]"
Command.ExecuteNonQuery()
Command.CommandText = "Grant SELECT to [test]"
Command.ExecuteNonQuery()

SQLServer.Close()

'SQL2k5 Username / Password:
Provider=SQLNCLI;Server=HostOrIP\Instance;Database =DatabaseName;Uid=myUsername;Pwd=myPassword;
'SQL2k5 Trusted Connection:
Provider=SQLNCLI;Server='HostOrIP;Database=Databas eName;Trusted_Connection=yes;

'SQL2k5 Username / Password: Provider=sqloledb;Data Source=' SQL2k5
Username / Password: ;Initial Catalog=DatabaseName;User
Id=myUsername;Password=myPassword;
'SQL2k5 Trusted Connection: Provider=sqloledb;Data Source=' SQL2k5
Username / Password: ;Initial Catalog=DatabaseName;Integrated
Security=SSPI;

Creates a SQL2k5 Database named test123 on primary (instance sqlsk5).
creates a table (test) with 2 fields (id integer as identity and test as
nvarchar). creates 2 user (1 windows, 1 sql) and logins to the new
database. grant full access to the windows- and only-select access to
sql-user.

thats all.

"tc" <tu**@idcodeware.co.ukschrieb im Newsbeitrag
news:OR**************@TK2MSFTNGP02.phx.gbl...
>Does anyone have an example of how to connect to an SQL server and create
a new database, then add a user and assign permissions? One problem is
that users may be user authenticated, not Windows authenticated.

Thanks.


Apr 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: heyitsme_ryan | last post by:
Ei guys I’m Ryan from Philippines, I need your advice and recommendations about Windows 2003 Server and SQL Server 2000 installation. Well, here’s the scenario. First is for windows 2003 server:...
8
by: Nils Magnus Englund | last post by:
Hello, I am having trouble using Integrated Windows Authentication between our intranet server and our database server, both of which are on our local domain. Windows authentication works for...
6
by: gerry | last post by:
I am almost at the end of my rope - I have to go through this process everytime a new version of studio is released or it is installed on a new machine - what a (^%&$^& pain. I am trying to...
5
by: lmttag | last post by:
ASP.NET 2.0 (C#) application Intranet application (not on the Internet) Using Windows authentication and impersonation Windows Server 2003 (IIS6) Server is a member server on a domain Logged...
5
by: =?Utf-8?B?QWRyaWFuTW9ycmlz?= | last post by:
Hello! I'm trying to copy a file from another computer on the network that I do not have permission with my current logon details to access. If I open the folder using the Windows file manager...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.