How to create a database in SQL Server?

Asked

Viewed 207 times

-1

I installed SQL Server, and comes Magnament Studio, how do I create my bank? I tried going there, and I had authenticated by Windows but it is error.

How I create my bank?

  • First you need to be able to authenticate, otherwise it’s difficult... If it does not work authenticating by Windows it is because you have not installed with this option enabled. You have the user password sa?

  • what is the password of the user sa? what is the login and password??

  • You must have created this password in the installation, only you know. If you have this information, log as user sa and SQL authentication (not Windows)

  • but it is not authenticating anything, if I have not put in the installation, as it is?

  • 2

    Dude, if nothing works, why not reinstall SQL? Pay attention to the installer, one of the steps is the authentication options.

  • And if you don’t know what to do during installation, maybe it can be answered here.

  • Try to take a look at this link, it has an installation tutorial, which you can follow: http://www.profissionaisti.com.br/2013/09/tutorial-instalacao-do-microsoft-sql-server-2012/

  • See if this helps: http://sqlserverzest.com/2013/08/20/sql-server-why-is-the-sa-login-account-disabled-how-to-enable-sa-login-account/

  • and this link can also be useful for you: http://www.lansweeper.com/kb/23/SQLserver-enable-mixed-authentication.html

  • pasta I’ll look at....

  • I’m reinstalling here...

  • how to move the conversation to a BP?

  • still no login, already reinstalled and see no user option sa, and still not working authentication in windows

Show 8 more comments

2 answers

3

The user must be valid either in SQL Server or even in Windows if using delegated authentication to the operating system.

using (var connection = new SqlConnection("data source=NomeDoServidor; uid=usuario; pwd=senha;")) {
using (var cmd = new SqlCommand()) {
    connection.Open();
    cmd.Connection = connection;
    cmd.CommandText = "create database NomeDoBancoDeDados;";
    cmd.ExecuteNonQuery();
    cmd.CommandText = "use NomeDoBancoDeDados; create table tabela (ID int, campo1 varchar(20));";
    cmd.ExecuteNonQuery();
}

I put in the Github for future reference.

Of course the creation of tables is an example, it is not necessary.

Alternative to the string connecting: "Server=localhost; Integrated security=SSPI; database=master"

Of course it can be sophisticated but this should work if you do not have installation and configuration problems in SQL Server. If you do, you need to review this part. Read the documentation before installing. Understand the implications of each choice.

More recently can do:

using var connection = new SqlConnection("data source=NomeDoServidor; uid=usuario; pwd=senha;"));
using var cmd = new SqlCommand());
connection.Open();
cmd.Connection = connection;
cmd.CommandText = "create database NomeDoBancoDeDados;";
cmd.ExecuteNonQuery();
cmd.CommandText = "use NomeDoBancoDeDados; create table tabela (ID int, campo1 varchar(20));";
cmd.ExecuteNonQuery();
  • the problem is, it is not authenticating anything. as I create a login?

  • 1

    But the question is how to create. It’s this way. You put the tag C#, I put how to create in C#. If the problem is different, the question should have reflected this. When you have doubt about authentication, if it’s not programming, you have to make it clear. So until it’s not whether the question would be on-topic. http://meta.pt.stackoverflow.com/questions/499/o-que-%C3%A9-o-problema-xy

  • I still can not enter the bank, already teinstalei, already tried with user sa, and with authentication in windows

  • It is very difficult without seeing every step done. It will not be easy for you to get help over the internet. It’s the kind of error that we can’t see because it happens.

  • Until today I could never, access the sql server on this machine, always gives the same error: Network error or specific to the instance when establishing connection with SQL Server.

  • already downloaded the 2012 Nterprise, marked it in the installation authentication by windows, and nothing so far.

Show 1 more comment

0


There is no secret to connect, let’s see the simple steps:

1 - In the server name option you put the name of your local pc, ex Name-Pc/user

2 - Brand windows Authentication and will connect.

No mistake.

  • Got it, the problem was that on behalf of the server I was putting only the name, and not in this way that Voce showed, vlw

  • @Warlock glad he was able to solve it. This was already written in my reply: NomeDoServidor, I guess you didn’t pay attention to this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.