Code:
NETRESOURCE nrMap = { 0 };
nrMap.dwType = RESOURCETYPE_DISK;
nrMap.lpLocalName = "Z:";
nrMap.lpRemoteName = "\\\\MyServer\\c$";
DWORD retCode = WNetAddConnection2(&nrMap, "mypassword", "myuser", 0 );
It's always a good idea to zero out api structures before use in case you don't specify every member. In this case, you are not providing a value for the lpProvider member.
The sample linked to from the WNetAddConnection2 documentation shows that it expects "Z:" rather than "Z:\\".
Anyone can read a password embedded in a program. Therefore, if you are connecting as admin they will have total access to the target machine. You may want to consider making an account for DB access and only give it the required access to the database.