Introduction to ADO.NET: A Simple Address Book • Chapter 7 |
345 |
Frequently Asked Questions
The following Frequently Asked Questions, answered by the authors of this book, are designed to both measure your understanding of the concepts presented in this chapter and to assist you with real-life implementation of these concepts. To have your questions about this chapter answered by the author, browse to www.syngress.com/solutions and click on the “Ask the Author” form.
Frequently Asked Questions
Q: Where is the best place to put the connection string?
A:In this chapter, we put our samples in the web.config file.This provides a central point to administer the connection strings, and allows for a reasonable level of security.You should guard the web.config from prying eyes regardless of where the connection string is.You really have a lot of options for placing the connection string.You can put the connection string in an encrypted in a file, custom object, and so on.The best place really depends on your environment, the applications purpose, and the level of security desired.
Q: Can I reuse a connection?
A:Yes, connections can be reused. Remember to test for state before you do, as ADO.NET may close the connection if it thinks it is not being used.You cannot use a connection twice at the same time. It would not be wise to open a connection at the application level, as you could very easily end up with simultaneous attempts to use the same connection.
Q:In SQL Server, which data type is more suitable for a primary key, INT, BIGINT or a uniqueidentifier?
A:Generally speaking, the INT going to be sufficient. An INT can hold between –2,147,483,648 and 2,147,483,648.That is a lot of records. If you were to seed an identity column with –2,147,483,648 negative number and insert one record a second, it would take 136 years to use all of them up. If you need more than that, then BIGINT is an alternative, but uniqueidentifier would probably be more appropriate.The other good use for the uniqueidentifier is to keep disconnected records from colliding with one another.This is often an issue with replication, and the uniqueidentifier is the method used to prevent it.