C
C#•2y ago
mr_rox

how to connect to sql server?

i want to connect to microsft sql server and i get error the the database doesnt exist and it is
33 Replies
x0rld 👻 🎃
what's your connection string ?
mr_rox
mr_roxOP•2y ago
string connectToServer = "Data Source=.;Integrated Security=True;Encrypt = False";
x0rld 👻 🎃
🤔
mr_rox
mr_roxOP•2y ago
Smadge ideas?
x0rld 👻 🎃
this sql query should give you the connection string
SELECT
'data source=' + @@SERVERNAME +
';initial catalog=' + DB_NAME() +
CASE type_desc
WHEN 'WINDOWS_LOGIN'
THEN ';trusted_connection=true'
ELSE
';user id=' + SUSER_NAME()
END
FROM sys.server_principals
WHERE name = suser_name()
SELECT
'data source=' + @@SERVERNAME +
';initial catalog=' + DB_NAME() +
CASE type_desc
WHEN 'WINDOWS_LOGIN'
THEN ';trusted_connection=true'
ELSE
';user id=' + SUSER_NAME()
END
FROM sys.server_principals
WHERE name = suser_name()
mr_rox
mr_roxOP•2y ago
x0rld 👻 🎃
do this in ssms
mr_rox
mr_roxOP•2y ago
what is ssms? .
x0rld 👻 🎃
what do you use as database explorer ? visual studio ?
mr_rox
mr_roxOP•2y ago
msms
x0rld 👻 🎃
🤔
mr_rox
mr_roxOP•2y ago
mssms Microsft sql server managment studio
x0rld 👻 🎃
i'm pretty sure you mean ssms xD
mr_rox
mr_roxOP•2y ago
but i doing it in c# visual studio
x0rld 👻 🎃
you need the correct connection string to connect to your database datasource should not be a dot
mr_rox
mr_roxOP•2y ago
the dot is localost
x0rld 👻 🎃
🤔
mr_rox
mr_roxOP•2y ago
mr_rox
mr_roxOP•2y ago
x0rld 👻 🎃
you don't have catalog in the connection string here
mr_rox
mr_roxOP•2y ago
string connectToServer = string.Format("Data Source=.;initial catalog={0};Integrated Security=True;Encrypt = False",database); con = new SqlConnection(connectToServer); .
x0rld 👻 🎃
i've always use that kind of connection string 🤔 Server=<URL>;Database=<NAME>;User ID=<USERNAME>;Password=<PASSWORD> ( by connecting using sql connection not windows )
mr_rox
mr_roxOP•2y ago
i think its login issue but i am not setting any password or username'
x0rld 👻 🎃
i think the default configuration use windows configuration
mr_rox
mr_roxOP•2y ago
i am using it
mr_rox
mr_roxOP•2y ago
mr_rox
mr_roxOP•2y ago
.
x0rld 👻 🎃
yeah that's what i meant idk how it works with that
mr_rox
mr_roxOP•2y ago
oh thx anyway
Pendramon
Pendramon•2y ago
Maybe you have multiple instances of SQL Server and . is pointing to a wrong one. Try connect to server on SSMS with . as server name and check if the database exists there.
mr_rox
mr_roxOP•2y ago
ok But its localhost so it points to the server that runs doesnt it?
Pendramon
Pendramon•2y ago
localhost points to the current device. You can have multiple SQL Server versions on a single device, default instance which is an unnamed instance, and named instances. There can only be one default instance, while you can have multiple named instances. The default instance is set by the installer and I personally do not know how to change it. So if you do localhost you will get the default instance, if you want to get a named instance you would have to do localhost/InstanceName
mr_rox
mr_roxOP•2y ago
Ok
Want results from more Discord servers?
Add your server