For Standard security:
connectStr = _T("Provider=sqloledb;Data Source=MyServerName;"
"Initial Catalog=MyDatabaseName;"
"User Id=MyUsername;Password=MyPassword;");
For Trusted Connection security (Microsoft Windows NT integrated security):
connectStr = _T("Provider=sqloledb;Data Source=MyServerName;"
"Initial Catalog=MyDatabaseName;"
"Integrated Security=SSPI;");
If you want to connect to a "Named Instance" (SQL Server 2000), you must to specify Data Source=Servere Name\Instance Name like in the following example:
connectStr = _T("Provider=sqloledb;Data Source=MyServerName\MyInstanceName;"
"Initial Catalog=MyDatabaseName;User Id=MyUsername;Password=MyPassword;");
If you want to connect with a SQL Server running on the same computer, you must specify the keyword (local) in the Data Source like in the following example:
connectStr = _T("Provider=sqloledb;Data Source=(local);"
"Initial Catalog=myDatabaseName;"
"User ID=myUsername;Password=myPassword;");
To connect to SQL Server running on a remote computer (via an IP address):
connectStr = _T("Provider=sqloledb;Network Library=DBMSSOCN;"
"Data Source=10.200.3.18,1433;"
"Initial Catalog=MyDatabaseName;User ID=MyUsername;"
"Password=MyPassword;");
沒有留言:
張貼留言