Evening, ive sucessfully managed to connect to a local copy of sqlserver via c# and input data into an existing database. Unfortunately im not too sure how to connect to the server and then create a database. Im assuming its possible??

If someone could point me in the right direct i would appreciate it.

"ve sucessfully managed to connect to a local copy of sqlserver via c# and input data into an existing database."

you need to do the same thing for a remote DB? can you pls explain yourself better

I have a copy of MS SQL server 2008 installed on my laptop and im trying to write a program which will connect to that server, create a table within a database and then read a .csv files and input that data into the table in the stated database.

The issue im having is that the database has to already exist and im hard coding the name of the database.

I would like to be able to connect to the server, create a new database, create a new table and then read and copy the .csv file into that table.

If this still doesnt make sense, please let me know. Thanks for taking the time to reply to my question.

Aye ok, I had originally tried to use the connectionstringbuilder to open a connection by ommiting the InitialCatalog statement but that didnt seem to work.

SqlConnectionStringBuilder cnStrBuilder = new SqlConnectionStringBuilder();
// Ommitted the below line but it didnt work
//cnStrBuilder["Initial Catalog"] = "AutoLot";
cnStrBuilder["Data Source"] = "(local)";
cnStrBuilder["Integrated Security"] = true;
cnStrBuilder["Connect Timeout"] = 30;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.