I always seem to get lost when trying to get to grips with BOL as it always confuses me?
For example I search on how to create a csv as a linked server and I find this:
VB.NET:
[URL="javascript:CopyCode('ctl00_LibFrame_ctl05VisualBasic');"][COLOR=#0000ff][/COLOR][/URL]
[COLOR=green]'Connect to the local, default instance of SQL Server.[/COLOR]
[COLOR=blue]Dim[/COLOR] srv [COLOR=blue]As[/COLOR] Server
srv = [COLOR=blue]New[/COLOR] Server
[COLOR=green]'Create a linked server.[/COLOR]
[COLOR=blue]Dim[/COLOR] lsrv [COLOR=blue]As[/COLOR] LinkedServer
lsrv = [COLOR=blue]New[/COLOR] LinkedServer(srv, [COLOR=maroon]"OLEDBSRV"[/COLOR])
[COLOR=green]'When the product name is SQL Server the remaining properties are not required to be set.[/COLOR]
lsrv.ProductName = [COLOR=maroon]"SQL Server"[/COLOR]
lsrv.Create()
No this does not help me as I dont understand what this has to do with csv?
So,
does......
javascript:CopyCode('ctl00_LibFrame_ctl05VisualBasic'); Dim srv As Server
srv = New Server
Create a server ojbect connected to my SQLExpress instance?
I know this makes a linked server, but to what? what is OLEDBSRV?
Dim lsrv As LinkedServer
lsrv = New LinkedServer(srv, "OLEDBSRV")
I know this makes an SQL Server link, but I want CSV!
lsrv.ProductName = "SQL Server" lsrv.Create()
I always find the BOL just whets my appetite leaving me stuck not know where to find the bits I am missing
javascript:CopyCode('ctl00_LibFrame_ctl05VisualBasic');
OK....for what it is worth my day has taken me on this journey...
This block of code creates a linked server named CSVIMPORT but I get the displayed error after trying to run a query against it
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] srvAdminServer [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Server = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cnSQLConnection [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlClient.SqlConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlConnection([/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Settings.MB2007ConnectionString)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] scnServerConnection [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ServerConnection = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] lsrvCSV [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] LinkedServer
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strsql [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#a31515]"SELECT * INTO user_import FROM CSVIMPORT...FullStatement$"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objCommand [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlClient.SqlCommand
cnSQLConnection.Open()
scnServerConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Microsoft.SqlServer.Management.Common.ServerConnection(cnSQLConnection)
[/SIZE][SIZE=2][COLOR=#008000]' create a server
[/COLOR][/SIZE][SIZE=2]srvAdminServer = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Server(scnServerConnection)
[/SIZE][SIZE=2][COLOR=#008000]' check if we have a linked server, there will only ever be one, delete it if present
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] srvAdminServer.LinkedServers.Count > 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]srvAdminServer.LinkedServers.Item(0).Drop()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' setup a new linked server
[/COLOR][/SIZE][SIZE=2]lsrvCSV = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] LinkedServer(srvAdminServer, [/SIZE][SIZE=2][COLOR=#a31515]"CSVIMPORT"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#008000]' set its properties
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] lsrvCSV
.ProviderName = [/SIZE][SIZE=2][COLOR=#a31515]"Microsoft.Jet.OLEDB.4.0"
[/COLOR][/SIZE][SIZE=2].ProductName = [/SIZE][SIZE=2][COLOR=#a31515]"Excel"
[/COLOR][/SIZE][SIZE=2].DataSource = [/SIZE][SIZE=2][COLOR=#a31515]"C:\FullStatement.csv"
[/COLOR][/SIZE][SIZE=2].ProviderString = [/SIZE][SIZE=2][COLOR=#a31515]"Excel 8.0"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]With
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]' creates ok with no errors
[/COLOR][/SIZE][SIZE=2]lsrvCSV.Create()
[/SIZE][SIZE=2][COLOR=#008000]' setup an sql command to run against linked server
[/COLOR][/SIZE][SIZE=2]objCommand = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlCommand(strsql, cnSQLConnection)
objCommand.CommandText = strsql
objCommand.ExecuteNonQuery()
[/SIZE][SIZE=2][COLOR=#008000]' doh!! get the following error
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'"The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "CSVIMPORT" reported an error. The provider did not give any information about the error.
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "CSVIMPORT"."
[/COLOR][/SIZE]
So I thought stuff this lets go back to the begining and did this:
Now I am back to square 1 where I get a message saying I cant do this as the component of my instance of SQL Express has ad hoc distributed querires turned off.
So I have trudged through the web and bol etc and found how to turn this on via SQL Surface Area Configuration.
But I still get the same error.
So I think I am missing something here?
Within SSMSE I do not see my applications .mdf file (does not seem to matter?)
Within the VB.NET 2005 IDE I have my .mdf as a connection in server explorer.
When my app connects to the .mdf file does it create a 'virtual sql express' instance and if so do I need to somehow progmatically turn on the setting in this instance?
Or am I off beam and it is only ever my .\SQLExpress instance involved and if so why does the setting now turned on not allow the query to run?
Lastly.....when the end user eventually installs my app thro the publish clickonce and the install downloads and installs sql express onto their computer how can I be sure it has the required setting turned on?
Please if anyone can help this is driving me bonkers
I feel that a linked server approach would be better, but from above you see I cannot get it to work.
If I go for ad hoc distributed queries from what I understand I have to alter the surface area of not only my instance (which even tho I have done this I still get an error saying it is disabled), but also the end user which they might not like the idea of.
I am searching and searching but am going round in circles....
Now this appears bleedin overly complicated for what I want, and although it imports an Excel spreadsheet (not csv as originally wanted) it does not import the very first row of the spreadsheet?
There are no column headings and even if I insert a blank row it still starts with the first row of data missing?
Come folkes, do you want me on my knees begging for help
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.