0

I search on the net in order to find the solution but all of them refer to the situation in which you must make connection with database that already exists.

In my case, I must make a connection with the server (localhost/SQLEXPRESS) and not create any database yet.

Just the connection with server.

Then, if connection is made, I will create database if necessary.

I get error on conn.Open() I tried:

var conn = new SqlConnection("Server=localhost\\SQLEXPRESS;Integrated Security=SSPI")

but as I said it doesn't work.

EDIT:

Ok, I understood that I must connect to some default database. Now I edited my connection string like this:

"Server=localhost\\SQLEXPRESS;Integrated Security=SSPI;database=master"

But I get error:

System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)'

jarlh
  • 42,561
  • 8
  • 45
  • 63

1 Answers1

0

No, it is not possible to connect to the database engine itself. What you can do is connect to the master database or any default database you might have like tempdb or Northwind.

Then, once connected to one of these database using an account with privilege high enough you can create database with TSQL quite easily.

In addition to your comment, login with windows account OR sql account does not matter. Either can have the default database setting set to i.e Master and then when you login the database is already specified by the account. I do not recommend this approach. Using Master which i am pretty sure that all version of express have by default is a much safer option.

Franck
  • 4,438
  • 1
  • 28
  • 55