希望能给出一个切实可用的例子或语句出来。
因为我看过MSDN后,自己在实现时,不知道如何处理UserID和PWD,如何填写,我试过总是失败。还有,就是SQL Server设置ODBC时,有几个步骤,如选择哪个数据库,这个该如何实现,因为默认的是master,而我用要的肯定不是这个master,谢谢。
BTW:开发环境是Visual C++
因为我看过MSDN后,自己在实现时,不知道如何处理UserID和PWD,如何填写,我试过总是失败。还有,就是SQL Server设置ODBC时,有几个步骤,如选择哪个数据库,这个该如何实现,因为默认的是master,而我用要的肯定不是这个master,谢谢。
BTW:开发环境是Visual C++
(LPSTR)"SQL Server",
(LPSTR)"DSN=dsnname\0"
"SERVER=small\0"
"DATABASE=databasename\0"))//添加一个ODBC数据源,其类型为
//SQL Server,服务器为small,名字为dsnname,数据库为databasename
"Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");For Trusted Connection security: (Microsoft Windows NT integrated security)strConnection = _T("Driver={SQL Server};Server=MyServerName;Database=myDatabaseName;Uid=;Pwd=;");Also you can use the parameter Trusted_Connection that indicates that you are using the Microsoft Windows NT Authentication Mode to authorize user access to the SQL Server database. For example:strConnection = _T("Driver={SQL Server};Server=MyServerName;Database=MyDatabaseName;"
"Trusted_Connection=yes;");If the Sql Server is running in the same computer you can replace the name of the server by the word (local) like in the following sample:strConnection = _T("Driver={SQL Server};Server=(local);"
"Database=MyDatabaseName;Uid=MyUserName;Pwd=MyPassword;");If you want to connect with a remote SQL Server you must to inform the address, the port, and the Network Library to use: The Address Parameter must be an IP Address and must to include the portThe Network Parameter can be one of the following: dbnmpntw Win32 Named Pipes dbmssocn Win32 Winsock TCP/IP dbmsspxn Win32 SPX/IPX dbmsvinn Win32 Banyan Vines dbmsrpcn Win32 Multi-Protocol (Windows RPC)
至于连接时的口令,和用户id在open函数中.
我的问题在于像small_wei(small)给出的,就差一个UID和PWD,然后,我直接加上"UID=sa\0WD=xxx\0",创建会失败.而这种用法,在对于mdb是可行的。所以,我很疑惑。
我试试,是不是不管它也行....
CDatabase
db.Open("hs",false,false,"ODBC;UID=hs;PWD=hs")