How can I specify a schema name in SQL ConnectionString using ASP.net dynamically. I have a single database with multiple schema. I need to fetch data from table belonging to particular schema.
Asked
Active
Viewed 1.6k times
2 Answers
6
You can only specify the database and user details in the connection string.
To retrieve data from a specific schema, you need to reference that schema in your query. For example;
SELECT field1, field2 FROM [Schema].[Table]
ChrisBint
- 12,658
- 6
- 36
- 56
2
I would like to reference here an older thread, which is definitely useful in this question:
Possible to set default schema from connection string?
You can only set the default schema to the user itself. You can try an ALTER USER statement, where you can define a default schema to the user. It means you can create a user to each schema, if that is what you need.
Community
- 1
- 1
András Ottó
- 7,469
- 1
- 28
- 37