vb.net - Method/Property Error on New SQL Server Connection -
i'm running vb .net in vs2013, on windows 8 on sql server 2008 r2, , creation of sql connection failing error:
property access must assign property or use value.
here's code:
dim ocnn sqlconnection dim scnn string dim bsuncnnok boolean
try if vssunserver <> "" scnn = "provider=sqloledb.1;" & _ "integrated security=sspi;" & _ "persist security info=false;" & _ "initial catalog=sunsystemsdata;" & _ "data source=" & vssunserver ocnn = new sqlconnection(scnn) ocnn.open() bsuncnnok = true end if catch ex exception bsuncnnok = false end try
_vssunserver_
string being passed in sub, , has run-time value of "svrsun07"
.
the error being raised on line:
ocnn = new sqlconnection(scnn)
so @ run-time, scnn holds:
"provider=sqloledb.1;integrated security=sspi;persist security info=false;initial catalog=sunsystemsdata;data source=svrsun07"
i've lifted connection string .udl file, returns successful when test connection.
i can run sqlsms on database ok.
below ascii art diagram shows how components related each other. trying use sql oledb connection string sqlconnection. these things don't go together.
c#/vb.net code -┬------------> sqlconnection -----------------┬-> sql server | | ├--> oledbconnection -┬-> sql oledb provider -┤ | | | | native code --┤ | | | | └-> odbcconnection ---┴-> sql odbc driver ----┘
if want use sql oledb native provider can use oledbconnection
. might useful if want vb.net code flexible , possible connect other oledb providers such access, postgres, mysql, etc.
however if know sure connecting sql server easier use sqlconnection
instead connection string "integrated security=sspi;persist security info=false;initial catalog=sunsystemsdata;data source=svrsun07"
.
Comments
Post a Comment