0

This code is written in WCF. when I add reference from localhost then this code works fine but when service reference is added from IIS then it fails in cn.Open() . It doesn't throw any exception and just hangs in this line.

        OdbcConnection cn = new OdbcConnection();
        cn.ConnectionString = "DSN=myDsn;Uid=myuid;Pwd=mypassword;";
        cn.Open(); // Fails on this line

Or is there any other way which which I can get datasource name with dsn in C#?

tom redfern
  • 30,562
  • 14
  • 91
  • 126
user270014
  • 581
  • 3
  • 21

1 Answers1

1

Makes sure the DSN was created as a system DSN and not a user DSN. If it's created as a user DSN (as you) then the IIS service user will not have access to it.

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
  • When you created the DSN did you select "With Windows NT authentication using network login ID" or "With SQL Server authentication using a login ID and password entered by the user"? – Peter Ritchie May 13 '12 at 16:44
  • Which driver did you use when you created the DSN? – Peter Ritchie May 13 '12 at 16:48
  • Not windows authentication, its SQL server authentication ...SQL Native client..yes if i use direct connection string it works . It even works from console but not from WCF – user270014 May 15 '12 at 16:24
  • Console and WCF run under different user contexts. Using a connection string instead of the DSN suggest there's some permissions thing t hat is keep the WCF user context from accessing the DSN. Without more detail, it's impossible to tell. Why is a connection string not sufficient? – Peter Ritchie May 15 '12 at 16:28