简体   繁体   中英

My SQL ODBC Connection working in console application but not working in Window Service

Initially my code was working fine on console application but not working on Window Service. I created text file inside catch to check if the code is connecting to MySQL or not and observed that this is the actual problem. What could be the reason of it?

I tried creating System DSN as well as UserDSN, but none of them work. My connection string is:

conn.ConnectionString = "DSN=TrAudit_SQL;Uid=marium;Pwd=marium;";

        try
        {
            conn.Open();
        }
        catch
        {

            return (-1);
        }

I've spent days with the same problem. The problem core appears to be very simple: The Build option "Prefer 32-bit.." of your project should match the version of driver used. So, when using 32-bit driver version on 64-bit OS, the oprion should be checked. Or, you can set it directly in .csproj file as:

<PropertyGroup ...>
    <DebugSymbols>true</DebugSymbols>
    ...
    <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM