✅ SQLConnection and queries to the database
Hey there!
I've been having this problem lately with something i'm writing, which essentially boils down to the following code:
When I run this, it seems to just not find my
Alunos
table, and I end up having to write [{database}].[dbo].[Alunos]
even though I had specified that I wanted to start out with a database in my connection string. What am I doing wrong here? I don't want to have to write my queries with dbo.(...)
; I'd rather just switch to the database I want at runtime and then query a table directly 😅19 Replies
When you do a select statement, normally it would be [{database}].[dbo].[Alunos] not dbo.[{database}.Alunos]. Your database name should come before the schema name (dbo).
I'm guessing something is wrong with the way your database is setup.
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
I was referring to when they mentioned dbo.[{database}.Alunos]
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
Oh- right I was just stupid and wrote it wrong
I'll edit it
That is how its written, I just copied it wrong lol
Oh wait no it isn't because there's
Escola.Alunos
at the end stillThe other thing I can suggest is change the first line so you just use $ instead of $@
assuming you have variables for
server
and database
Yep, I do, and that didn't seem to work, but after getting your insight... I think I know what's happening
But just to confirm it...
When ... I create a table like this... I'm creating a table named
"Escola.Alunos"
right?yep.
Escola.Alunos
is now your table name.God damnit. Thank you so much
That's embarassing
it happens to all of us
It should be
[Escola].[Alunos]
right?is Escola your database name?
Yeah
you can just do
Alunos
if you are running the create statement in the Escola database
then you can SELECT * FROM Alunos if you are connected to the Escola databaseYep, thank you!
$close
Use the /close command to mark a forum thread as answered